ofctl_v1_2/3: IPv4 dotted decimal subnet mask support
This enables to_match_ip() to accept IPv4 address with dotted decimal subnet mask or ACL hybrid CIDR. Given 3 match field values below: '192.168.1.0/24' '192.168.1.0/255.255.255.0' '192.168.1.0/0.0.0.255' These addresses are logically equivalent. Signed-off-by: Wei-Li Tang <alextwl@xinguard.com> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
parent
5ce9e31b65
commit
d5ec1f2079
|
@ -326,17 +326,8 @@ def to_match_tpdst(value, match, rest):
|
|||
|
||||
|
||||
def to_match_ip(value):
|
||||
ip_mask = value.split('/')
|
||||
# ip
|
||||
ipv4 = struct.unpack('!I', socket.inet_aton(ip_mask[0]))[0]
|
||||
# netmask
|
||||
mask = 32
|
||||
if len(ip_mask) == 2:
|
||||
mask = int(ip_mask[1])
|
||||
netmask = ofproto_v1_2_parser.UINT32_MAX << 32 - mask\
|
||||
& ofproto_v1_2_parser.UINT32_MAX
|
||||
|
||||
return ipv4, netmask
|
||||
ip = netaddr.IPNetwork(value)
|
||||
return ip.ip.value, ip.netmask.value
|
||||
|
||||
|
||||
def to_match_ipv6(value):
|
||||
|
|
|
@ -368,17 +368,8 @@ def to_match_tpdst(value, match, rest):
|
|||
|
||||
|
||||
def to_match_ip(value):
|
||||
ip_mask = value.split('/')
|
||||
# ip
|
||||
ipv4 = struct.unpack('!I', socket.inet_aton(ip_mask[0]))[0]
|
||||
# netmask
|
||||
mask = 32
|
||||
if len(ip_mask) == 2:
|
||||
mask = int(ip_mask[1])
|
||||
netmask = ofproto_v1_3_parser.UINT32_MAX << 32 - mask\
|
||||
& ofproto_v1_3_parser.UINT32_MAX
|
||||
|
||||
return ipv4, netmask
|
||||
ip = netaddr.IPNetwork(value)
|
||||
return ip.ip.value, ip.netmask.value
|
||||
|
||||
|
||||
def to_match_ipv6(value):
|
||||
|
|
Loading…
Reference in New Issue