Skip to content

Commit b565fc0

Browse files
authored
Merge pull request #47 from CESNET/bugfix/ipv6fragment
bugfix for IPv6 messages - empty fragment should be empty string not …
2 parents 60f716b + 2c53049 commit b565fc0

File tree

2 files changed

+17
-53
lines changed

2 files changed

+17
-53
lines changed

flowapp/__about__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.0.1"
1+
__version__ = "1.0.2"

flowapp/messages.py

Lines changed: 16 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,7 @@ def create_ipv4(rule, message_type=ANNOUNCE):
2525

2626
flagstring = rule.flags.replace(";", " ") if rule.flags else ""
2727

28-
flags = (
29-
"tcp-flags {};".format(flagstring)
30-
if rule.flags and rule.protocol == "tcp"
31-
else ""
32-
)
28+
flags = "tcp-flags {};".format(flagstring) if rule.flags and rule.protocol == "tcp" else ""
3329

3430
fragment_string = rule.fragment.replace(";", " ") if rule.fragment else ""
3531
fragment = "fragment [ {} ];".format(fragment_string) if rule.fragment else ""
@@ -55,11 +51,7 @@ def create_ipv6(rule, message_type=ANNOUNCE):
5551
if rule.next_header and rule.next_header != "all":
5652
protocol = "next-header ={};".format(IPV6_NEXT_HEADER[rule.next_header])
5753
flagstring = rule.flags.replace(";", " ")
58-
flags = (
59-
"tcp-flags {};".format(flagstring)
60-
if rule.flags and rule.next_header == "tcp"
61-
else ""
62-
)
54+
flags = "tcp-flags {};".format(flagstring) if rule.flags and rule.next_header == "tcp" else ""
6355

6456
spec = {"protocol": protocol, "mask": IPV6_DEFMASK, "flags": flags}
6557

@@ -103,25 +95,17 @@ def create_rtbh(rule, message_type=ANNOUNCE):
10395
targets = current_app.config["MULTI_NEIGHBOR"].get(rule.community.comm)
10496
else:
10597
targets = current_app.config["MULTI_NEIGHBOR"].get("primary")
106-
98+
10799
neighbor = prepare_multi_neighbor(targets)
108100
else:
109101
neighbor = ""
110102
except KeyError:
111103
neighbor = ""
112104

113-
community_string = (
114-
"community [{}]".format(rule.community.comm) if rule.community.comm else ""
115-
)
116-
large_community_string = (
117-
"large-community [{}]".format(rule.community.larcomm)
118-
if rule.community.larcomm
119-
else ""
120-
)
105+
community_string = "community [{}]".format(rule.community.comm) if rule.community.comm else ""
106+
large_community_string = "large-community [{}]".format(rule.community.larcomm) if rule.community.larcomm else ""
121107
extended_community_string = (
122-
"extended-community [{}]".format(rule.community.extcomm)
123-
if rule.community.extcomm
124-
else ""
108+
"extended-community [{}]".format(rule.community.extcomm) if rule.community.extcomm else ""
125109
)
126110

127111
as_path_string = ""
@@ -165,49 +149,29 @@ def create_message(rule, ipv_specific, message_type=ANNOUNCE):
165149
source = "source {}".format(rule.source) if rule.source else ""
166150
source += "/{};".format(smask) if rule.source else ""
167151

168-
source_port = (
169-
"source-port {};".format(trps(rule.source_port)) if rule.source_port else ""
170-
)
152+
source_port = "source-port {};".format(trps(rule.source_port)) if rule.source_port else ""
171153

172154
dmask = sanitize_mask(rule.dest_mask, ipv_specific["mask"])
173155
dest = " destination {}".format(rule.dest) if rule.dest else ""
174156
dest += "/{};".format(dmask) if rule.dest else ""
175157

176-
dest_port = (
177-
"destination-port {};".format(trps(rule.dest_port)) if rule.dest_port else ""
178-
)
158+
dest_port = "destination-port {};".format(trps(rule.dest_port)) if rule.dest_port else ""
179159

180-
protocol = ipv_specific["protocol"]
181-
flags = ipv_specific["flags"]
182-
fragment = ipv_specific.get("fragment", None)
160+
protocol = ipv_specific.get("protocol", "")
161+
flags = ipv_specific.get("flags", "")
162+
fragment = ipv_specific.get("fragment", "")
183163

184-
packet_len = (
185-
"packet-length {};".format(trps(rule.packet_len, MAX_PACKET))
186-
if rule.packet_len
187-
else ""
188-
)
164+
packet_len = "packet-length {};".format(trps(rule.packet_len, MAX_PACKET)) if rule.packet_len else ""
189165

190-
match_body = "{source} {source_port} {dest} {dest_port} {protocol} {fragment} {flags} {packet_len}".format(
191-
source=source,
192-
source_port=source_port,
193-
dest=dest,
194-
dest_port=dest_port,
195-
protocol=protocol,
196-
fragment=fragment,
197-
flags=flags,
198-
packet_len=packet_len,
199-
)
166+
values = [source, source_port, dest, dest_port, protocol, fragment, flags, packet_len]
167+
match_body = " ".join(v for v in values if v)
200168

201169
command = "{};".format(rule.action.command)
202170

203171
try:
204172
if current_app.config["USE_RD"]:
205-
rd_string = "route-distinguisher {rd};".format(
206-
rd=current_app.config["RD_STRING"]
207-
)
208-
rt_string = "extended-community target:{rt};".format(
209-
rt=current_app.config["RT_STRING"]
210-
)
173+
rd_string = "route-distinguisher {rd};".format(rd=current_app.config["RD_STRING"])
174+
rt_string = "extended-community target:{rt};".format(rt=current_app.config["RT_STRING"])
211175
else:
212176
rd_string = ""
213177
rt_string = ""

0 commit comments

Comments
 (0)