Last active
March 31, 2017 19:56
-
-
Save joestringer/7357e4a034fd90f570d0 to your computer and use it in GitHub Desktop.
Convert OVS key attributes into readable text
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import sys | |
from enum import Enum | |
class Key_attr(Enum): | |
# From Linux include/uapi/linux/openvswitch.h | |
OVS_KEY_ATTR_UNSPEC = 0 | |
OVS_KEY_ATTR_ENCAP = 1 | |
OVS_KEY_ATTR_PRIORITY = 2 | |
OVS_KEY_ATTR_IN_PORT = 3 | |
OVS_KEY_ATTR_ETHERNET = 4 | |
OVS_KEY_ATTR_VLAN = 5 | |
OVS_KEY_ATTR_ETHERTYPE = 6 | |
OVS_KEY_ATTR_IPV4 = 7 | |
OVS_KEY_ATTR_IPV6 = 8 | |
OVS_KEY_ATTR_TCP = 9 | |
OVS_KEY_ATTR_UDP = 10 | |
OVS_KEY_ATTR_ICMP = 11 | |
OVS_KEY_ATTR_ICMPV6 = 12 | |
OVS_KEY_ATTR_ARP = 13 | |
OVS_KEY_ATTR_ND = 14 | |
OVS_KEY_ATTR_SKB_MARK = 15 | |
OVS_KEY_ATTR_TUNNEL = 16 | |
OVS_KEY_ATTR_SCTP = 17 | |
OVS_KEY_ATTR_TCP_FLAGS = 18 | |
OVS_KEY_ATTR_DP_HASH = 19 | |
OVS_KEY_ATTR_RECIRC_ID = 20 | |
OVS_KEY_ATTR_MPLS = 21 | |
OVS_KEY_ATTR_CT_STATE = 22 | |
OVS_KEY_ATTR_CT_ZONE = 23 | |
OVS_KEY_ATTR_CT_MARK = 24 | |
OVS_KEY_ATTR_CT_LABELS = 25 | |
def print_keys(value): | |
for name, member in Key_attr.__members__.items(): | |
if value & (1 << member.value): | |
print("\t%s, " % name) | |
print() | |
def main(): | |
if len(sys.argv) < 2: | |
sys.exit('Usage: %s <mask> [allowed]' % sys.argv[0]) | |
v1 = int(sys.argv[1], 16) | |
v2 = 0 | |
if len(sys.argv) > 2: | |
v2 = int(sys.argv[2], 16) | |
print("Initial mask:") | |
print_keys(v1) | |
if v2: | |
print("Allowed mask:") | |
print_keys(v2) | |
print("mask & ~allowed:") | |
print_keys(v1 & ~v2) | |
print("allowed & ~mask:") | |
print_keys(v2 & ~v1) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment