Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
FoD
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
David Schmitz
FoD
Commits
7a8a4da4
Commit
7a8a4da4
authored
13 years ago
by
Leonidas Poulopoulos
Browse files
Options
Downloads
Patches
Plain Diff
Changed models logic. Decreased FKs
parent
064ecc91
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
flowspec/models.py
+32
-93
32 additions, 93 deletions
flowspec/models.py
with
32 additions
and
93 deletions
flowspec/models.py
+
32
−
93
View file @
7a8a4da4
...
@@ -63,44 +63,7 @@ class MatchDscp(models.Model):
...
@@ -63,44 +63,7 @@ class MatchDscp(models.Model):
class
Meta
:
class
Meta
:
db_table
=
u
'
match_dscp
'
db_table
=
u
'
match_dscp
'
class
MatchFragmentType
(
models
.
Model
):
fragmenttype
=
models
.
CharField
(
max_length
=
20
,
choices
=
FRAGMENT_CODES
)
def
__unicode__
(
self
):
return
self
.
fragmenttype
class
Meta
:
db_table
=
u
'
match_fragment_type
'
class
MatchIcmpCode
(
models
.
Model
):
icmp_code
=
models
.
CharField
(
max_length
=
64
)
def
__unicode__
(
self
):
return
self
.
icmp_code
class
Meta
:
db_table
=
u
'
match_icmp_code
'
class
MatchIcmpType
(
models
.
Model
):
icmp_type
=
models
.
CharField
(
max_length
=
64
)
class
Meta
:
db_table
=
u
'
match_icmp_type
'
class
MatchPacketLength
(
models
.
Model
):
packet_length
=
models
.
IntegerField
()
class
Meta
:
db_table
=
u
'
match_packet_length
'
class
MatchProtocol
(
models
.
Model
):
protocol
=
models
.
CharField
(
max_length
=
64
)
def
__unicode__
(
self
):
return
self
.
protocol
class
Meta
:
db_table
=
u
'
match_protocol
'
class
MatchTcpFlag
(
models
.
Model
):
tcp_flag
=
models
.
CharField
(
max_length
=
255
)
def
__unicode__
(
self
):
return
self
.
tcp_flag
class
Meta
:
db_table
=
u
'
match_tcp_flag
'
class
ThenAction
(
models
.
Model
):
class
ThenAction
(
models
.
Model
):
action
=
models
.
CharField
(
max_length
=
60
,
choices
=
THEN_CHOICES
)
action
=
models
.
CharField
(
max_length
=
60
,
choices
=
THEN_CHOICES
)
action_value
=
models
.
CharField
(
max_length
=
255
,
blank
=
True
,
null
=
True
)
action_value
=
models
.
CharField
(
max_length
=
255
,
blank
=
True
,
null
=
True
)
...
@@ -109,68 +72,29 @@ class ThenAction(models.Model):
...
@@ -109,68 +72,29 @@ class ThenAction(models.Model):
class
Meta
:
class
Meta
:
db_table
=
u
'
then_action
'
db_table
=
u
'
then_action
'
class
ThenStatement
(
models
.
Model
):
thenaction
=
models
.
ManyToManyField
(
ThenAction
)
class
Meta
:
db_table
=
u
'
then
'
class
MatchStatement
(
models
.
Model
):
matchDestination
=
models
.
ForeignKey
(
MatchAddress
,
blank
=
True
,
null
=
True
,
related_name
=
"
matchDestination
"
)
matchDestinationPort
=
models
.
ManyToManyField
(
MatchPort
,
blank
=
True
,
null
=
True
,
related_name
=
"
matchDestinationPort
"
)
matchdscp
=
models
.
ManyToManyField
(
MatchDscp
,
blank
=
True
,
null
=
True
)
matchfragmenttype
=
models
.
ForeignKey
(
MatchFragmentType
,
blank
=
True
,
null
=
True
)
matchicmpcode
=
models
.
ForeignKey
(
MatchIcmpCode
,
blank
=
True
,
null
=
True
)
matchicmptype
=
models
.
ForeignKey
(
MatchIcmpType
,
blank
=
True
,
null
=
True
)
matchpacketlength
=
models
.
ForeignKey
(
MatchPacketLength
,
blank
=
True
,
null
=
True
)
matchport
=
models
.
ManyToManyField
(
MatchPort
,
blank
=
True
,
null
=
True
,
related_name
=
"
matchPort
"
)
matchprotocol
=
models
.
ForeignKey
(
MatchProtocol
,
blank
=
True
,
null
=
True
)
matchSource
=
models
.
ForeignKey
(
MatchAddress
,
blank
=
True
,
null
=
True
,
related_name
=
"
matchSource
"
)
matchSourcePort
=
models
.
ManyToManyField
(
MatchPort
,
blank
=
True
,
null
=
True
,
related_name
=
"
matchSourcePort
"
)
matchTcpFlag
=
models
.
ForeignKey
(
MatchTcpFlag
,
blank
=
True
,
null
=
True
)
# def clean(self, *args, **kwargs):
# clean_error = True
# from django.core.exceptions import ValidationError
# if not (self.matchDestination or self.matchfragmenttype or self.matchicmpcode or self.matchicmptype
# or self.matchpacketlength or self.matchprotocol or self.matchSource or self.matchTcpFlag):
# clean_error = False
# try:
# assert(self.matchDestinationPort)
# clean_error = False
# except:
# pass
# try:
# assert(self.matchSourcePort)
# clean_error = False
# except:
# pass
# try:
# assert(self.matchport)
# clean_error = False
# except:
# pass
# try:
# print self.matchdscp
# assert(self.matchdscp)
# clean_error = False
# except:
# pass
# if clean_error:
# raise ValidationError('At least one match statement has to be declared')
class
Meta
:
db_table
=
u
'
match
'
class
Route
(
models
.
Model
):
class
Route
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
128
)
name
=
models
.
CharField
(
max_length
=
128
)
applier
=
models
.
ForeignKey
(
User
)
applier
=
models
.
ForeignKey
(
User
)
match
=
models
.
ForeignKey
(
MatchStatement
)
destination
=
models
.
CharField
(
max_length
=
32
,
blank
=
True
,
null
=
True
,
help_text
=
u
"
Network address. Use address/CIDR notation
"
)
then
=
models
.
ForeignKey
(
ThenStatement
)
destinationport
=
models
.
ManyToManyField
(
MatchPort
,
blank
=
True
,
null
=
True
,
related_name
=
"
matchDestinationPort
"
)
dscp
=
models
.
ManyToManyField
(
MatchDscp
,
blank
=
True
,
null
=
True
)
fragmenttype
=
models
.
CharField
(
max_length
=
20
,
choices
=
FRAGMENT_CODES
,
blank
=
True
,
null
=
True
)
icmpcode
=
models
.
CharField
(
max_length
=
32
,
blank
=
True
,
null
=
True
)
icmptype
=
models
.
CharField
(
max_length
=
32
,
blank
=
True
,
null
=
True
)
packetlength
=
models
.
IntegerField
(
blank
=
True
,
null
=
True
)
port
=
models
.
ManyToManyField
(
MatchPort
,
blank
=
True
,
null
=
True
,
related_name
=
"
matchPort
"
)
protocol
=
models
.
CharField
(
max_length
=
32
,
blank
=
True
,
null
=
True
)
source
=
models
.
CharField
(
max_length
=
32
,
blank
=
True
,
null
=
True
,
help_text
=
u
"
Network address. Use address/CIDR notation
"
)
sourceport
=
models
.
ManyToManyField
(
MatchPort
,
blank
=
True
,
null
=
True
,
related_name
=
"
matchSourcePort
"
)
tcpflag
=
models
.
CharField
(
max_length
=
128
,
blank
=
True
,
null
=
True
)
then
=
models
.
ManyToManyField
(
ThenAction
)
filed
=
models
.
DateTimeField
(
auto_now_add
=
True
)
filed
=
models
.
DateTimeField
(
auto_now_add
=
True
)
last_updated
=
models
.
DateTimeField
(
auto_now
=
True
)
last_updated
=
models
.
DateTimeField
(
auto_now
=
True
)
is_online
=
models
.
BooleanField
(
default
=
False
)
is_online
=
models
.
BooleanField
(
default
=
False
)
is_active
=
models
.
BooleanField
(
default
=
False
)
expires
=
models
.
DateTimeField
()
expires
=
models
.
DateTimeField
()
response
=
models
.
CharField
(
max_length
=
512
,
blank
=
True
,
null
=
True
)
response
=
models
.
CharField
(
max_length
=
512
,
blank
=
True
,
null
=
True
)
comments
=
models
.
TextField
(
null
=
True
,
blank
=
True
)
def
__unicode__
(
self
):
def
__unicode__
(
self
):
...
@@ -178,7 +102,22 @@ class Route(models.Model):
...
@@ -178,7 +102,22 @@ class Route(models.Model):
class
Meta
:
class
Meta
:
db_table
=
u
'
route
'
db_table
=
u
'
route
'
def
clean
(
self
,
*
args
,
**
kwargs
):
from
django.core.exceptions
import
ValidationError
if
self
.
destination
:
try
:
address
=
IPNetwork
(
self
.
address
)
self
.
address
=
address
.
exploded
except
Exception
:
raise
ValidationError
(
'
Invalid network address format
'
)
if
self
.
source
:
try
:
address
=
IPNetwork
(
self
.
address
)
self
.
address
=
address
.
exploded
except
Exception
:
raise
ValidationError
(
'
Invalid network address format
'
)
def
save
(
self
,
*
args
,
**
kwargs
):
def
save
(
self
,
*
args
,
**
kwargs
):
applier
=
PR
.
Applier
(
route_object
=
self
)
applier
=
PR
.
Applier
(
route_object
=
self
)
commit
,
response
=
applier
.
apply
()
commit
,
response
=
applier
.
apply
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment