Accept None as destination (to use the default route) in SourceIP(6)Field

This commit is contained in:
Pierre LALET 2017-01-14 14:28:19 +01:00 committed by Guillaume Valadon
parent 8dfafd7852
commit 39b3002b5e
2 changed files with 18 additions and 18 deletions

View File

@ -268,15 +268,15 @@ class SourceIPField(IPField):
if conf.route is None:
# unused import, only to initialize conf.route
import scapy.route
dst=getattr(pkt,self.dstname)
if isinstance(dst,Gen):
r = map(conf.route.route, dst)
r.sort()
if r[0] != r[-1]:
warning("More than one possible route for %s"%repr(dst))
iff,x,gw = r[0]
dst = ("0.0.0.0" if self.dstname is None else
getattr(pkt, self.dstname))
if isinstance(dst, (Gen, list)):
r = {conf.route.route(daddr) for daddr in dst}
if len(r) > 1:
warning("More than one possible route for %r" % (dst,))
x = min(r)[1]
else:
iff,x,gw = conf.route.route(dst)
x = conf.route.route(dst)[1]
return IPField.i2h(self, pkt, x)

View File

@ -247,17 +247,17 @@ class SourceIP6Field(IP6Field):
return IP6Field.i2m(self, pkt, x)
def i2h(self, pkt, x):
if x is None:
dst=getattr(pkt,self.dstname)
if isinstance(dst,Gen):
r = map(conf.route6.route, dst)
r.sort()
if r[0] == r[-1]:
x=r[0][1]
else:
warning("More than one possible route for %s"%repr(dst))
return None
if conf.route6 is None:
# unused import, only to initialize conf.route6
import scapy.route6
dst = ("::" if self.dstname is None else getattr(pkt, self.dstname))
if isinstance(dst, (Gen, list)):
r = {conf.route6.route(daddr) for daddr in dst}
if len(r) > 1:
warning("More than one possible route for %r" % (dst,))
x = min(r)[1]
else:
iff,x,nh = conf.route6.route(dst)
x = conf.route6.route(dst)[1]
return IP6Field.i2h(self, pkt, x)
class DestIP6Field(IP6Field, DestField):