OVS vport, datapath, flow_table, flex_array, sw_flow

来源:互联网 发布:剑灵优化补丁 编辑:程序博客网 时间:2024/06/01 08:53
dev_table在kernel里面有好多重名的数据结构,可以先改一下名字:# git diffdiff --git a/net/openvswitch/vport.c b/net/openvswitch/vport.cindex b6c8524..554b919 100644--- a/net/openvswitch/vport.c+++ b/net/openvswitch/vport.c@@ -37,7 +37,7 @@ static LIST_HEAD(vport_ops_list); /* Protected by RCU read lock for reading, ovs_mutex for writing. */-static struct hlist_head *dev_table;+static struct hlist_head *dev_table_ovs; #define VPORT_HASH_BUCKETS 1024 /**@@ -47,9 +47,9 @@  */ int ovs_vport_init(void) {-       dev_table = kzalloc(VPORT_HASH_BUCKETS * sizeof(struct hlist_head),+       dev_table_ovs = kzalloc(VPORT_HASH_BUCKETS * sizeof(struct hlist_head),                            GFP_KERNEL);-       if (!dev_table)+       if (!dev_table_ovs)                return -ENOMEM;        return 0;@@ -62,13 +62,13 @@ int ovs_vport_init(void)  */ void ovs_vport_exit(void) {-       kfree(dev_table);+       kfree(dev_table_ovs); } static struct hlist_head *hash_bucket(const struct net *net, const char *name) {        unsigned int hash = jhash(name, strlen(name), (unsigned long) net);-       return &dev_table[hash & (VPORT_HASH_BUCKETS - 1)];+       return &dev_table_ovs[hash & (VPORT_HASH_BUCKETS - 1)]; } int __ovs_vport_ops_register(struct vport_ops *ops)再用crash增加一个命令vp:void print_dp(ulong dp){        int n = 0;        int j, k;        char *ufid_str;        int offset;        int ufid_count;        fprintf(fp, "datapath %p\n", dp);        ulong table = dp + MEMBER_OFFSET("datapath", "table");        fprintf(fp, "flow_table %p\n", table);        ulong mask_list = table + MEMBER_OFFSET("flow_table", "mask_list");        ufid_count = (int)read_pointer2(table, "flow_table", "ufid_count");        fprintf(fp, "ufid_count %x\n", ufid_count);        if (ufid_count) {                ufid_str = "ufid_ti";                offset = MEMBER_OFFSET("sw_flow", "ufid_table");        } else {                ufid_str = "ti";                offset = MEMBER_OFFSET("sw_flow", "flow_table");        }        fprintf(fp, "list -H %p -l sw_flow_mask.list -s sw_flow_mask\n", mask_list);        ulong ufid_ti = read_pointer2(table, "flow_table", ufid_str);        fprintf(fp, "table_instance %p\n", ufid_ti);        ulong flex_array = read_pointer1(ufid_ti);        fprintf(fp, "flex_array %p\n", flex_array);        ulong parts = flex_array + MEMBER_OFFSET("flex_array", "parts");        fprintf(fp, "rd %p 2\n", parts);        ulong part;        for(j = 0; j < 2; j ++) {                part = read_pointer1(parts + j * 8);                fprintf(fp, "rd %p 512\n", part);                ulong flow;                ulong key;                ulong eth;                for (k = 0; k < 512; k ++) {                        flow = read_pointer1(part + k * 8);                        if (flow) {                                n++;                                fprintf(fp, "\tsw_flow -l 0x%x %p\n", offset, flow);                                key = flow + MEMBER_OFFSET("sw_flow", "key") - offset;                                fprintf(fp, "\t\tsw_flow_key %p\n", key);                                eth = key + MEMBER_OFFSET("sw_flow_key", "eth");                                fprintf(fp, "\t\trd -8 %p 12\n", eth);                        }                }        }        fprintf(fp, "flows number: %d\n", n);} voidcmd_vp(void){        int i;        char buf[BUFSIZE];        ulong dp = 0, old_dp = 0;        int c;        int n = 0;        int offset;        int verbose = 1;        // -u non-ufid        while ((c = getopt(argcnt, args, "uv")) != EOF) {                switch (c) {                case 'v':                        verbose = 0;                        break;                default:                        return;                }        }        offset = MEMBER_OFFSET("vport", "hash_node");        ulong dev_table_ovs = symbol_value("dev_table_ovs");        dev_table_ovs = read_pointer1(dev_table_ovs);        fprintf(fp, "dev_table_ovs: %llx\n", dev_table_ovs);        for (i = 0; i < 1024; i++) {                ulong vport = read_pointer1(dev_table_ovs + i * 8);                if (vport) {                        ulong dev = read_pointer2(vport - offset, "vport", "dev");                        get_device_name(dev, buf);                        fprintf(fp, "\n%-6s\n", buf);                        fprintf(fp, "list %llx -l vport.hash_node -s vport\n", vport);                        dp = read_pointer2(vport - 0x20, "vport", "dp");                        if (dp && dp != old_dp && n != 2 && verbose) {                                print_dp(dp);                                old_dp = dp;                                n++;                        }                }        }}# ovs-dpctl showsystem@ovs-system:        lookups: hit:7856981 missed:24170 lost:2788        flows: 2        masks: hit:17676385 total:3 hit/pkt:2.24        port 0: ovs-system (internal)        port 1: eth0        port 2: vxlan_sys_4789 (vxlan)        port 3: eth1        port 4: br1 (internal)# ovs-vsctl showa04b8fc4-a249-4ac4-86b8-956036e84341    Bridge "br1"        Port "br1"            Interface "br1"                type: internal        Port "eth1"            Interface "eth1"        Port "vxlan0"            Interface "vxlan0"                type: vxlan                options: {key="1", remote_ip="192.168.1.19"}        Port "eth0"            Interface "eth0"    ovs_version: "2.7.90"# ovs-dpctl dump-flows system@ovs-systemrecirc_id(0),tunnel(tun_id=0x1,src=192.168.1.19,dst=192.168.1.18,flags(-df-csum+key)),in_port(2),eth(src=0a:5e:73:d8:72:45,dst=02:25:d0:e2:18:50),eth_type(0x0800),ipv4(frag=no), packets:13495, bytes:1322510, used:0.272s, actions:1recirc_id(0),in_port(1),eth(src=02:25:d0:e2:18:50,dst=0a:5e:73:d8:72:45),eth_type(0x0800),ipv4(tos=0/0x3,frag=no), packets:13495, bytes:1322510, used:0.272s, actions:set(tunnel(tun_id=0x1,dst=192.168.1.19,ttl=64,tp_dst=4789,flags(df|key))),2crash> vpdev_table_ovs: ffff880b0dc00000eth1list ffff880c86c21620 -l vport.hash_node -s vportdatapath 0xffff880c85f36900flow_table 0xffff880c85f36920ufid_count 4list -H 0xffff880c85f36930 -l sw_flow_mask.list -s sw_flow_masktable_instance 0xffff880af6834640flex_array 0xffff880c50571000rd 0xffff880c50571018 2rd 0xffff880c50570000 512        sw_flow -l 0x38 0xffff880c52755198                sw_flow_key 0xffff880c527551c8                rd -8 0xffff880c52755314 12        sw_flow -l 0x38 0xffff880c062f1778                sw_flow_key 0xffff880c062f17a8                rd -8 0xffff880c062f18f4 12rd 0xffff880c50577000 512        sw_flow -l 0x38 0xffff880c78951f38                sw_flow_key 0xffff880c78951f68                rd -8 0xffff880c789520b4 12        sw_flow -l 0x38 0xffff880af4194218                sw_flow_key 0xffff880af4194248                rd -8 0xffff880af4194394 12flows number: 4br1list ffff880c86c21fa0 -l vport.hash_node -s vportvxlan_sys_4789list ffff880c547ee5a0 -l vport.hash_node -s vportdp1list ffff880c538835a0 -l vport.hash_node -s vportdatapath 0xffff880c53883480flow_table 0xffff880c538834a0ufid_count 0list -H 0xffff880c538834b0 -l sw_flow_mask.list -s sw_flow_masktable_instance 0xffff880c494f7240flex_array 0xffff880c51023000rd 0xffff880c51023018 2rd 0xffff880c51025000 512rd 0xffff880c51027000 512        sw_flow -l 0x10 0xffff880c801d5170                sw_flow_key 0xffff880c801d51c8                rd -8 0xffff880c801d5314 12flows number: 1ovs-systemlist ffff880c85f36420 -l vport.hash_node -s vporteth0list ffff880aeefc4020 -l vport.hash_node -s vport
crash>        sw_flow -l 0x38 0xffff880af4194218
struct sw_flow { rcu = { next = 0x0, func = 0x0 }, flow_table = { node = {{ next = 0x0, pprev = 0xffff880c534b94b0 }, { next = 0x0, pprev = 0xffff880c876fec00 }}, hash = 0x7d5e97f2 }, ufid_table = { node = {{ next = 0x0, pprev = 0xffff880c50577a10 }, { next = 0x0, pprev = 0x0 }}, hash = 0x8ca22d3f }, stats_last_writer = 0xd, key = { tun_opts = "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", tun_opts_len = 0x0, tun_key = { tun_id = 0x100000000000000, # tun_id = 1 u = { ipv4 = { src = 0x1301a8c0, # 192.168.1.19 dst = 0x1201a8c0 # 192.168.1.18 }, ipv6 = { src = { in6_u = { u6_addr8 = "\300\250\001\023\300\250\001\022\000\000\000\000\000\000\000", u6_addr16 = {0xa8c0, 0x1301, 0xa8c0, 0x1201, 0x0, 0x0, 0x0, 0x0}, u6_addr32 = {0x1301a8c0, 0x1201a8c0, 0x0, 0x0} } }, dst = { in6_u = { u6_addr8 = "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", u6_addr16 = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, u6_addr32 = {0x0, 0x0, 0x0, 0x0} } } } }, tun_flags = 0x400, tos = 0x0, ttl = 0x0, label = 0x0, tp_src = 0x0, tp_dst = 0x0 }, phy = { priority = 0x0, skb_mark = 0x0, in_port = 0x2 }, mac_proto = 0x1, # MAC_PROTO_ETHERNET tun_proto = 0x2, # AF_INET ovs_flow_hash = 0x0, recirc_id = 0x0, eth = { src = "\n^s\330rE", dst = "\002%\320\342\030P", vlan = { tpid = 0x0, tci = 0x0 }, cvlan = { tpid = 0x0, tci = 0x0 }, type = 0x8 },... id = { ufid_len = 0x10, { ufid = {0x4415c45b, 0xf0a8484e, 0x9b8456be, 0x82ab2e35}, unmasked_key = 0xf0a8484e4415c45b } }, mask = 0xffff880b5cafa400, sf_acts = 0xffff880be05ecb40, stats = 0xffff880af4194440}crash> rd -8 0xffff880af4194394 12ffff880af4194394: 0a 5e 73 d8 72 45 02 25 d0 e2 18 50 .^s.rE.%...P# ovs-dpctl add-flow $dp \ "in_port(1),eth(),eth_type(0x800),\ ipv4(src=1.1.1.1,dst=2.2.2.2)" 2If inserting a rule using ovs-dpctl:crash> vp -udev_table_ovs: ffff880b0dc00000eth1list ffff880c86c21620 -l vport.hash_node -s vportdatapath 0xffff880c85f36900flow_table 0xffff880c85f36920list -H 0xffff880c85f36930 -l sw_flow_mask.list -s sw_flow_masktable_instance 0xffff880afdcd1a80flex_array 0xffff880c534be000rd 0xffff880c534be018 2rd 0xffff880c534b8000 512 sw_flow -l 0x10 0xffff880c52755180 sw_flow_key 0xffff880c527551d8 rd -8 0xffff880c52755324 12 sw_flow -l 0x10 0xffff880af4194200 sw_flow_key 0xffff880af4194258 rd -8 0xffff880af41943a4 12rd 0xffff880c534ba000 512 sw_flow -l 0x10 0xffff880af4e3be20 sw_flow_key 0xffff880af4e3be78 rd -8 0xffff880af4e3bfc4 12 sw_flow -l 0x10 0xffff880c5cd4c9c0 sw_flow_key 0xffff880c5cd4ca18 rd -8 0xffff880c5cd4cb64 12flows number: 4br1list ffff880c86c21fa0 -l vport.hash_node -s vportvxlan_sys_4789list ffff880c547ee5a0 -l vport.hash_node -s vportdp1list ffff880c538835a0 -l vport.hash_node -s vportdatapath 0xffff880c53883480flow_table 0xffff880c538834a0list -H 0xffff880c538834b0 -l sw_flow_mask.list -s sw_flow_masktable_instance 0xffff880c494f7240flex_array 0xffff880c51023000rd 0xffff880c51023018 2rd 0xffff880c51025000 512rd 0xffff880c51027000 512 sw_flow -l 0x10 0xffff880c801d5170 sw_flow_key 0xffff880c801d51c8 rd -8 0xffff880c801d5314 12flows number: 1ovs-systemlist ffff880c85f36420 -l vport.hash_node -s vporteth0list ffff880aeefc4020 -l vport.hash_node -s vportstruct sw_flow_key { tun_opts = "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", tun_opts_len = 0x0, tun_key = { tun_id = 0x0, u = { ipv4 = { src = 0x0, dst = 0x0 }, ipv6 = { src = { in6_u = { u6_addr8 = "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", u6_addr16 = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, u6_addr32 = {0x0, 0x0, 0x0, 0x0} } }, dst = { in6_u = { u6_addr8 = "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", u6_addr16 = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, u6_addr32 = {0x0, 0x0, 0x0, 0x0} } } } }, tun_flags = 0x0, tos = 0x0, ttl = 0x0, label = 0x0, tp_src = 0x0, tp_dst = 0x0 }, phy = { priority = 0x0, skb_mark = 0x0, in_port = 0x1 }, mac_proto = 0x1, tun_proto = 0x0, ovs_flow_hash = 0x0, recirc_id = 0x0, eth = { src = "\000\000\000\000\000", dst = "\000\000\000\000\000", vlan = { tpid = 0x0, tci = 0x0 }, cvlan = { tpid = 0x0, tci = 0x0 }, type = 0x8 }, ct_state = 0x0, ct_orig_proto = 0x0, { mpls = { top_lse = 0x0 }, ip = { proto = 0x0, tos = 0x0, ttl = 0x0, frag = 0x0 } }, ct_zone = 0x0, tp = { src = 0x0, dst = 0x0, flags = 0x0 }, { ipv4 = { addr = { src = 0x1010101, # 1.1.1.1 dst = 0x2020202 # 2.2.2.2 }, { ct_orig = { src = 0x0, dst = 0x0 }, arp = { sha = "\000\000\000\000\000", tha = "\000\000\000\000\000" } } },...


原创粉丝点击