[PATCH v2 0/4] Fix errors raised by Coverity tool
by Eduardo Lima (Etrunko)
From: "Eduardo Lima (Etrunko)" <eblima(a)br.ibm.com>
Yet another series of patches fixing errors revealed by Coverity tool. It would
be nice if we had a similar setup so we could run the tool on a regular basis. I
started playing with clang a while ago. It also provides a static analyser, but
I could not complete the setup by then.
https://bugzilla.redhat.com/show_bug.cgi?id=750418
Changes from v1:
- Fix compilation error in Patch 1
Best regards, Etrunko
Eduardo Lima (Etrunko) (4):
libxkutil: Fix possible NULL dereferences
Fix possible memory leaks
xml_parse_test: Fix invalid dereference
Fix possible use of unitialized variables
libxkutil/cs_util_instance.c | 5 +++++
libxkutil/device_parsing.c | 14 +++++++-------
libxkutil/pool_parsing.c | 5 +++--
libxkutil/xml_parse_test.c | 3 +--
libxkutil/xmlgen.c | 8 +++++---
src/Virt_AppliedFilterList.c | 3 ++-
src/Virt_Device.c | 20 ++++++++++++++++++++
src/Virt_DevicePool.c | 19 ++++++++++++++++++-
src/Virt_SwitchService.c | 24 ++++++++++++++++++++----
src/Virt_VirtualSystemManagementService.c | 16 ++++++++--------
src/Virt_VirtualSystemSnapshotService.c | 2 +-
11 files changed, 90 insertions(+), 29 deletions(-)
--
1.7.7.5
12 years, 7 months
[PATCH v3 00/10] VLAN extension - ReadOnly functions
by Wayne Xia
These patches would try introduce 4 class with readonly functionality.
It used libnl-3 and libbridge as static libarary as an implemention.
Program libnetwork_test would be generated under ./libnetwork/.libs/ .
Testing:
wbemcli -nl ein http://[]:[]@localhost:5988/root/virt:Net_VirtualEthernetSwitchSystem
wbemcli -nl ein http://[]:[]@localhost:5988/root/virt:Net_VirtualEthernetSwitchSystemSettingData
wbemcli -nl ein http://[]:[]@localhost:5988/root/virt:Net_EthernetPort
wbemcli -nl ein http://[]:[]@localhost:5988/root/virt:Net_EthernetPortAllocationSettingData
try with command vconfig and brctl modifying the system.
Note:
These patch only applys on libvirt-cim-0.5.15, Will try move it to 0.6.0
with libvirt 0.9.4 on RH6 on v4 patch.
repository:
git://gitorious.org/~xiaxia347/libvirt-cim/xiaxia347s-xiawenc.git
branch vlan_v3
https://gitorious.org/libvirt-cim/xiaxia347s-xiawenc/trees/vlan_v3
Wayne Xia (10):
add source code of libbridge and libnl-3
building system modification for libnl3 and libbridge
building system of libnetwork linking with libnl3 and libbridge
libnetwork source code with a test program
add a CIM model helper in libxkutil
CIM model - Makefile change
CIM model - VESS
CIM model - VESSSD
CIM model - EthernetPort
CIM model - EASD
Makefile.am | 14 +-
configure.ac | 19 +-
libnetwork/Makefile.am | 39 +
libnetwork/dll_magic.h | 13 +
libnetwork/host_network_API.c | 30 +
libnetwork/host_network_API.h | 25 +
libnetwork/host_network_basic.c | 657 ++++++
libnetwork/host_network_basic.h | 170 ++
libnetwork/host_network_error.h | 31 +
libnetwork/host_network_helper.c | 659 ++++++
libnetwork/host_network_helper.h | 202 ++
libnetwork/host_network_implement_OSAPI.c | 453 ++++
libnetwork/host_network_implement_OSAPI.h | 21 +
libnetwork/libbridge/.gitignore | 2 +
libnetwork/libbridge/Makefile.am | 20 +
libnetwork/libbridge/libbridge.h | 119 +
libnetwork/libbridge/libbridge_devif.c | 442 ++++
libnetwork/libbridge/libbridge_if.c | 117 +
libnetwork/libbridge/libbridge_init.c | 213 ++
libnetwork/libbridge/libbridge_misc.c | 51 +
libnetwork/libbridge/libbridge_private.h | 56 +
libnetwork/libnetwork_test.c | 82 +
libnetwork/libnl3/Makefile.am | 8 +
libnetwork/libnl3/include/Makefile.am | 122 +
libnetwork/libnl3/include/linux/fib_rules.h | 69 +
libnetwork/libnl3/include/linux/gen_stats.h | 67 +
libnetwork/libnl3/include/linux/genetlink.h | 83 +
libnetwork/libnl3/include/linux/if.h | 140 ++
libnetwork/libnl3/include/linux/if_addr.h | 55 +
libnetwork/libnl3/include/linux/if_arp.h | 156 ++
libnetwork/libnl3/include/linux/if_ether.h | 125 ++
libnetwork/libnl3/include/linux/if_link.h | 377 ++++
libnetwork/libnl3/include/linux/if_vlan.h | 62 +
libnetwork/libnl3/include/linux/inetdevice.h | 36 +
libnetwork/libnl3/include/linux/ip_mp_alg.h | 22 +
libnetwork/libnl3/include/linux/ipv6.h | 146 ++
libnetwork/libnl3/include/linux/neighbour.h | 155 ++
libnetwork/libnl3/include/linux/netfilter.h | 57 +
.../libnl3/include/linux/netfilter/nfnetlink.h | 60 +
.../include/linux/netfilter/nfnetlink_conntrack.h | 140 ++
.../libnl3/include/linux/netfilter/nfnetlink_log.h | 97 +
.../include/linux/netfilter/nfnetlink_queue.h | 94 +
libnetwork/libnl3/include/linux/netlink.h | 149 ++
libnetwork/libnl3/include/linux/pkt_cls.h | 467 ++++
libnetwork/libnl3/include/linux/pkt_sched.h | 606 +++++
libnetwork/libnl3/include/linux/rtnetlink.h | 605 +++++
libnetwork/libnl3/include/linux/snmp.h | 270 +++
.../libnl3/include/linux/tc_ematch/tc_em_meta.h | 89 +
libnetwork/libnl3/include/netlink-generic.h | 20 +
libnetwork/libnl3/include/netlink-local.h | 213 ++
libnetwork/libnl3/include/netlink-tc.h | 55 +
libnetwork/libnl3/include/netlink-types.h | 846 +++++++
libnetwork/libnl3/include/netlink/addr.h | 66 +
libnetwork/libnl3/include/netlink/attr.h | 283 +++
libnetwork/libnl3/include/netlink/cache-api.h | 230 ++
libnetwork/libnl3/include/netlink/cache.h | 134 ++
libnetwork/libnl3/include/netlink/cli/addr.h | 32 +
libnetwork/libnl3/include/netlink/cli/class.h | 21 +
libnetwork/libnl3/include/netlink/cli/cls.h | 24 +
libnetwork/libnl3/include/netlink/cli/ct.h | 34 +
libnetwork/libnl3/include/netlink/cli/link.h | 30 +
libnetwork/libnl3/include/netlink/cli/neigh.h | 27 +
libnetwork/libnl3/include/netlink/cli/qdisc.h | 23 +
libnetwork/libnl3/include/netlink/cli/route.h | 34 +
libnetwork/libnl3/include/netlink/cli/rule.h | 21 +
libnetwork/libnl3/include/netlink/cli/tc.h | 39 +
libnetwork/libnl3/include/netlink/cli/utils.h | 82 +
libnetwork/libnl3/include/netlink/data.h | 41 +
libnetwork/libnl3/include/netlink/errno.h | 64 +
.../libnl3/include/netlink/fib_lookup/lookup.h | 42 +
.../libnl3/include/netlink/fib_lookup/request.h | 51 +
libnetwork/libnl3/include/netlink/genl/ctrl.h | 40 +
libnetwork/libnl3/include/netlink/genl/family.h | 53 +
libnetwork/libnl3/include/netlink/genl/genl.h | 46 +
libnetwork/libnl3/include/netlink/genl/mngt.h | 87 +
libnetwork/libnl3/include/netlink/handlers.h | 146 ++
libnetwork/libnl3/include/netlink/list.h | 93 +
libnetwork/libnl3/include/netlink/msg.h | 147 ++
libnetwork/libnl3/include/netlink/netfilter/ct.h | 126 ++
libnetwork/libnl3/include/netlink/netfilter/log.h | 109 +
.../libnl3/include/netlink/netfilter/log_msg.h | 98 +
.../libnl3/include/netlink/netfilter/netfilter.h | 31 +
libnetwork/libnl3/include/netlink/netfilter/nfnl.h | 44 +
.../libnl3/include/netlink/netfilter/queue.h | 90 +
.../libnl3/include/netlink/netfilter/queue_msg.h | 104 +
libnetwork/libnl3/include/netlink/netlink-compat.h | 50 +
libnetwork/libnl3/include/netlink/netlink-kernel.h | 293 +++
libnetwork/libnl3/include/netlink/netlink.h | 93 +
libnetwork/libnl3/include/netlink/object-api.h | 348 +++
libnetwork/libnl3/include/netlink/object.h | 70 +
libnetwork/libnl3/include/netlink/route/addr.h | 98 +
libnetwork/libnl3/include/netlink/route/class.h | 66 +
.../libnl3/include/netlink/route/classifier.h | 51 +
.../libnl3/include/netlink/route/cls/basic.h | 31 +
.../libnl3/include/netlink/route/cls/cgroup.h | 30 +
.../libnl3/include/netlink/route/cls/ematch.h | 95 +
.../libnl3/include/netlink/route/cls/ematch/cmp.h | 32 +
.../libnl3/include/netlink/route/cls/ematch/meta.h | 41 +
.../include/netlink/route/cls/ematch/nbyte.h | 36 +
.../libnl3/include/netlink/route/cls/ematch/text.h | 42 +
libnetwork/libnl3/include/netlink/route/cls/fw.h | 29 +
.../libnl3/include/netlink/route/cls/police.h | 29 +
libnetwork/libnl3/include/netlink/route/cls/u32.h | 43 +
libnetwork/libnl3/include/netlink/route/link.h | 217 ++
libnetwork/libnl3/include/netlink/route/link/api.h | 134 ++
.../libnl3/include/netlink/route/link/bonding.h | 37 +
.../libnl3/include/netlink/route/link/inet.h | 29 +
.../libnl3/include/netlink/route/link/info-api.h | 20 +
.../libnl3/include/netlink/route/link/vlan.h | 57 +
.../libnl3/include/netlink/route/neighbour.h | 79 +
libnetwork/libnl3/include/netlink/route/neightbl.h | 65 +
libnetwork/libnl3/include/netlink/route/nexthop.h | 65 +
libnetwork/libnl3/include/netlink/route/pktloc.h | 49 +
libnetwork/libnl3/include/netlink/route/qdisc.h | 73 +
.../libnl3/include/netlink/route/qdisc/cbq.h | 30 +
.../libnl3/include/netlink/route/qdisc/dsmark.h | 41 +
.../libnl3/include/netlink/route/qdisc/fifo.h | 28 +
.../libnl3/include/netlink/route/qdisc/htb.h | 47 +
.../libnl3/include/netlink/route/qdisc/netem.h | 75 +
.../libnl3/include/netlink/route/qdisc/prio.h | 53 +
.../libnl3/include/netlink/route/qdisc/red.h | 17 +
.../libnl3/include/netlink/route/qdisc/sfq.h | 36 +
.../libnl3/include/netlink/route/qdisc/tbf.h | 40 +
libnetwork/libnl3/include/netlink/route/route.h | 124 +
libnetwork/libnl3/include/netlink/route/rtnl.h | 69 +
libnetwork/libnl3/include/netlink/route/rule.h | 75 +
libnetwork/libnl3/include/netlink/route/tc-api.h | 143 ++
libnetwork/libnl3/include/netlink/route/tc.h | 105 +
libnetwork/libnl3/include/netlink/socket.h | 69 +
libnetwork/libnl3/include/netlink/types.h | 110 +
libnetwork/libnl3/include/netlink/utils.h | 85 +
libnetwork/libnl3/include/netlink/version.h | 28 +
libnetwork/libnl3/include/netlink/version.h.in | 28 +
libnetwork/libnl3/lib/Makefile.am | 99 +
libnetwork/libnl3/lib/addr.c | 918 ++++++++
libnetwork/libnl3/lib/attr.c | 1213 ++++++++++
libnetwork/libnl3/lib/cache.c | 965 ++++++++
libnetwork/libnl3/lib/cache_mngr.c | 391 ++++
libnetwork/libnl3/lib/cache_mngt.c | 256 +++
libnetwork/libnl3/lib/cli/cls/basic.c | 93 +
libnetwork/libnl3/lib/cli/cls/cgroup.c | 75 +
libnetwork/libnl3/lib/cli/qdisc/bfifo.c | 83 +
libnetwork/libnl3/lib/cli/qdisc/blackhole.c | 64 +
libnetwork/libnl3/lib/cli/qdisc/htb.c | 203 ++
libnetwork/libnl3/lib/cli/qdisc/pfifo.c | 77 +
libnetwork/libnl3/lib/data.c | 186 ++
libnetwork/libnl3/lib/defs.h | 85 +
libnetwork/libnl3/lib/defs.h.in | 84 +
libnetwork/libnl3/lib/error.c | 116 +
libnetwork/libnl3/lib/fib_lookup/lookup.c | 348 +++
libnetwork/libnl3/lib/fib_lookup/request.c | 185 ++
libnetwork/libnl3/lib/genl/ctrl.c | 380 ++++
libnetwork/libnl3/lib/genl/family.c | 316 +++
libnetwork/libnl3/lib/genl/genl.c | 268 +++
libnetwork/libnl3/lib/genl/mngt.c | 273 +++
libnetwork/libnl3/lib/handlers.c | 395 ++++
libnetwork/libnl3/lib/msg.c | 1050 +++++++++
libnetwork/libnl3/lib/netfilter/ct.c | 601 +++++
libnetwork/libnl3/lib/netfilter/ct_obj.c | 785 +++++++
libnetwork/libnl3/lib/netfilter/log.c | 251 +++
libnetwork/libnl3/lib/netfilter/log_msg.c | 209 ++
libnetwork/libnl3/lib/netfilter/log_msg_obj.c | 458 ++++
libnetwork/libnl3/lib/netfilter/log_obj.c | 287 +++
libnetwork/libnl3/lib/netfilter/netfilter.c | 53 +
libnetwork/libnl3/lib/netfilter/nfnl.c | 245 ++
libnetwork/libnl3/lib/netfilter/queue.c | 251 +++
libnetwork/libnl3/lib/netfilter/queue_msg.c | 284 +++
libnetwork/libnl3/lib/netfilter/queue_msg_obj.c | 492 ++++
libnetwork/libnl3/lib/netfilter/queue_obj.c | 215 ++
libnetwork/libnl3/lib/nl.c | 896 ++++++++
libnetwork/libnl3/lib/object.c | 395 ++++
libnetwork/libnl3/lib/route/addr.c | 1054 +++++++++
libnetwork/libnl3/lib/route/class.c | 473 ++++
libnetwork/libnl3/lib/route/classid.c | 441 ++++
libnetwork/libnl3/lib/route/cls.c | 441 ++++
libnetwork/libnl3/lib/route/cls/basic.c | 229 ++
libnetwork/libnl3/lib/route/cls/cgroup.c | 189 ++
libnetwork/libnl3/lib/route/cls/ematch.c | 701 ++++++
libnetwork/libnl3/lib/route/cls/ematch/cmp.c | 93 +
libnetwork/libnl3/lib/route/cls/ematch/container.c | 41 +
libnetwork/libnl3/lib/route/cls/ematch/meta.c | 334 +++
libnetwork/libnl3/lib/route/cls/ematch/nbyte.c | 139 ++
libnetwork/libnl3/lib/route/cls/ematch/text.c | 183 ++
libnetwork/libnl3/lib/route/cls/ematch_grammar.l | 162 ++
libnetwork/libnl3/lib/route/cls/ematch_syntax.y | 497 +++++
libnetwork/libnl3/lib/route/cls/fw.c | 190 ++
libnetwork/libnl3/lib/route/cls/police.c | 66 +
libnetwork/libnl3/lib/route/cls/u32.c | 551 +++++
libnetwork/libnl3/lib/route/link.c | 2342 ++++++++++++++++++++
libnetwork/libnl3/lib/route/link/api.c | 316 +++
libnetwork/libnl3/lib/route/link/bonding.c | 217 ++
libnetwork/libnl3/lib/route/link/bridge.c | 83 +
libnetwork/libnl3/lib/route/link/dummy.c | 40 +
libnetwork/libnl3/lib/route/link/inet.c | 280 +++
libnetwork/libnl3/lib/route/link/inet6.c | 377 ++++
libnetwork/libnl3/lib/route/link/vlan.c | 565 +++++
libnetwork/libnl3/lib/route/neigh.c | 846 +++++++
libnetwork/libnl3/lib/route/neightbl.c | 815 +++++++
libnetwork/libnl3/lib/route/nexthop.c | 290 +++
libnetwork/libnl3/lib/route/pktloc.c | 260 +++
libnetwork/libnl3/lib/route/pktloc_grammar.l | 51 +
libnetwork/libnl3/lib/route/pktloc_syntax.y | 103 +
libnetwork/libnl3/lib/route/qdisc.c | 575 +++++
libnetwork/libnl3/lib/route/qdisc/blackhole.c | 37 +
libnetwork/libnl3/lib/route/qdisc/cbq.c | 204 ++
libnetwork/libnl3/lib/route/qdisc/dsmark.c | 413 ++++
libnetwork/libnl3/lib/route/qdisc/fifo.c | 169 ++
libnetwork/libnl3/lib/route/qdisc/htb.c | 643 ++++++
libnetwork/libnl3/lib/route/qdisc/netem.c | 906 ++++++++
libnetwork/libnl3/lib/route/qdisc/prio.c | 294 +++
libnetwork/libnl3/lib/route/qdisc/red.c | 190 ++
libnetwork/libnl3/lib/route/qdisc/sfq.c | 256 +++
libnetwork/libnl3/lib/route/qdisc/tbf.c | 460 ++++
libnetwork/libnl3/lib/route/route.c | 202 ++
libnetwork/libnl3/lib/route/route_obj.c | 1148 ++++++++++
libnetwork/libnl3/lib/route/route_utils.c | 171 ++
libnetwork/libnl3/lib/route/rtnl.c | 124 +
libnetwork/libnl3/lib/route/rule.c | 753 +++++++
libnetwork/libnl3/lib/route/tc.c | 1069 +++++++++
libnetwork/libnl3/lib/socket.c | 628 ++++++
libnetwork/libnl3/lib/stamp-h1 | 1 +
libnetwork/libnl3/lib/utils.c | 1040 +++++++++
libxkutil/Makefile.am | 12 +-
libxkutil/network_model_helper.c | 466 ++++
libxkutil/network_model_helper.h | 105 +
schema/EthernetPort.mof | 4 +
schema/EthernetPort.registration | 3 +
schema/EthernetPortAllocationSettingData.mof | 21 +
.../EthernetPortAllocationSettingData.registration | 3 +
schema/VirtualEthernetSwitchSystem.mof | 10 +
schema/VirtualEthernetSwitchSystem.registration | 3 +
schema/VirtualEthernetSwitchSystemSettingData.mof | 27 +
...ualEthernetSwitchSystemSettingData.registration | 3 +
src/Makefile.am | 23 +-
src/Virt_EASD.c | 729 ++++++
src/Virt_EASD.h | 59 +
src/Virt_EthernetPort.c | 561 +++++
src/Virt_EthernetPort.h | 58 +
src/Virt_VESSSD.c | 372 ++++
src/Virt_VESSSD.h | 39 +
src/Virt_VirtualEthernetSwitchSystem.c | 477 ++++
src/Virt_VirtualEthernetSwitchSystem.h | 52 +
242 files changed, 53037 insertions(+), 10 deletions(-)
create mode 100644 libnetwork/Makefile.am
create mode 100644 libnetwork/dll_magic.h
create mode 100644 libnetwork/host_network_API.c
create mode 100644 libnetwork/host_network_API.h
create mode 100644 libnetwork/host_network_basic.c
create mode 100644 libnetwork/host_network_basic.h
create mode 100644 libnetwork/host_network_error.h
create mode 100644 libnetwork/host_network_helper.c
create mode 100644 libnetwork/host_network_helper.h
create mode 100644 libnetwork/host_network_implement_OSAPI.c
create mode 100644 libnetwork/host_network_implement_OSAPI.h
create mode 100755 libnetwork/libbridge/.gitignore
create mode 100644 libnetwork/libbridge/Makefile.am
create mode 100644 libnetwork/libbridge/libbridge.h
create mode 100644 libnetwork/libbridge/libbridge_devif.c
create mode 100644 libnetwork/libbridge/libbridge_if.c
create mode 100644 libnetwork/libbridge/libbridge_init.c
create mode 100644 libnetwork/libbridge/libbridge_misc.c
create mode 100644 libnetwork/libbridge/libbridge_private.h
create mode 100644 libnetwork/libnetwork_test.c
create mode 100644 libnetwork/libnl3/Makefile.am
create mode 100644 libnetwork/libnl3/include/Makefile.am
create mode 100644 libnetwork/libnl3/include/linux/fib_rules.h
create mode 100644 libnetwork/libnl3/include/linux/gen_stats.h
create mode 100644 libnetwork/libnl3/include/linux/genetlink.h
create mode 100644 libnetwork/libnl3/include/linux/if.h
create mode 100644 libnetwork/libnl3/include/linux/if_addr.h
create mode 100644 libnetwork/libnl3/include/linux/if_arp.h
create mode 100644 libnetwork/libnl3/include/linux/if_ether.h
create mode 100644 libnetwork/libnl3/include/linux/if_link.h
create mode 100644 libnetwork/libnl3/include/linux/if_vlan.h
create mode 100644 libnetwork/libnl3/include/linux/inetdevice.h
create mode 100644 libnetwork/libnl3/include/linux/ip_mp_alg.h
create mode 100644 libnetwork/libnl3/include/linux/ipv6.h
create mode 100644 libnetwork/libnl3/include/linux/neighbour.h
create mode 100644 libnetwork/libnl3/include/linux/netfilter.h
create mode 100644 libnetwork/libnl3/include/linux/netfilter/nfnetlink.h
create mode 100644 libnetwork/libnl3/include/linux/netfilter/nfnetlink_conntrack.h
create mode 100644 libnetwork/libnl3/include/linux/netfilter/nfnetlink_log.h
create mode 100644 libnetwork/libnl3/include/linux/netfilter/nfnetlink_queue.h
create mode 100644 libnetwork/libnl3/include/linux/netlink.h
create mode 100644 libnetwork/libnl3/include/linux/pkt_cls.h
create mode 100644 libnetwork/libnl3/include/linux/pkt_sched.h
create mode 100644 libnetwork/libnl3/include/linux/rtnetlink.h
create mode 100644 libnetwork/libnl3/include/linux/snmp.h
create mode 100644 libnetwork/libnl3/include/linux/tc_ematch/tc_em_meta.h
create mode 100644 libnetwork/libnl3/include/netlink-generic.h
create mode 100644 libnetwork/libnl3/include/netlink-local.h
create mode 100644 libnetwork/libnl3/include/netlink-tc.h
create mode 100644 libnetwork/libnl3/include/netlink-types.h
create mode 100644 libnetwork/libnl3/include/netlink/addr.h
create mode 100644 libnetwork/libnl3/include/netlink/attr.h
create mode 100644 libnetwork/libnl3/include/netlink/cache-api.h
create mode 100644 libnetwork/libnl3/include/netlink/cache.h
create mode 100644 libnetwork/libnl3/include/netlink/cli/addr.h
create mode 100644 libnetwork/libnl3/include/netlink/cli/class.h
create mode 100644 libnetwork/libnl3/include/netlink/cli/cls.h
create mode 100644 libnetwork/libnl3/include/netlink/cli/ct.h
create mode 100644 libnetwork/libnl3/include/netlink/cli/link.h
create mode 100644 libnetwork/libnl3/include/netlink/cli/neigh.h
create mode 100644 libnetwork/libnl3/include/netlink/cli/qdisc.h
create mode 100644 libnetwork/libnl3/include/netlink/cli/route.h
create mode 100644 libnetwork/libnl3/include/netlink/cli/rule.h
create mode 100644 libnetwork/libnl3/include/netlink/cli/tc.h
create mode 100644 libnetwork/libnl3/include/netlink/cli/utils.h
create mode 100644 libnetwork/libnl3/include/netlink/data.h
create mode 100644 libnetwork/libnl3/include/netlink/errno.h
create mode 100644 libnetwork/libnl3/include/netlink/fib_lookup/lookup.h
create mode 100644 libnetwork/libnl3/include/netlink/fib_lookup/request.h
create mode 100644 libnetwork/libnl3/include/netlink/genl/ctrl.h
create mode 100644 libnetwork/libnl3/include/netlink/genl/family.h
create mode 100644 libnetwork/libnl3/include/netlink/genl/genl.h
create mode 100644 libnetwork/libnl3/include/netlink/genl/mngt.h
create mode 100644 libnetwork/libnl3/include/netlink/handlers.h
create mode 100644 libnetwork/libnl3/include/netlink/list.h
create mode 100644 libnetwork/libnl3/include/netlink/msg.h
create mode 100644 libnetwork/libnl3/include/netlink/netfilter/ct.h
create mode 100644 libnetwork/libnl3/include/netlink/netfilter/log.h
create mode 100644 libnetwork/libnl3/include/netlink/netfilter/log_msg.h
create mode 100644 libnetwork/libnl3/include/netlink/netfilter/netfilter.h
create mode 100644 libnetwork/libnl3/include/netlink/netfilter/nfnl.h
create mode 100644 libnetwork/libnl3/include/netlink/netfilter/queue.h
create mode 100644 libnetwork/libnl3/include/netlink/netfilter/queue_msg.h
create mode 100644 libnetwork/libnl3/include/netlink/netlink-compat.h
create mode 100644 libnetwork/libnl3/include/netlink/netlink-kernel.h
create mode 100644 libnetwork/libnl3/include/netlink/netlink.h
create mode 100644 libnetwork/libnl3/include/netlink/object-api.h
create mode 100644 libnetwork/libnl3/include/netlink/object.h
create mode 100644 libnetwork/libnl3/include/netlink/route/addr.h
create mode 100644 libnetwork/libnl3/include/netlink/route/class.h
create mode 100644 libnetwork/libnl3/include/netlink/route/classifier.h
create mode 100644 libnetwork/libnl3/include/netlink/route/cls/basic.h
create mode 100644 libnetwork/libnl3/include/netlink/route/cls/cgroup.h
create mode 100644 libnetwork/libnl3/include/netlink/route/cls/ematch.h
create mode 100644 libnetwork/libnl3/include/netlink/route/cls/ematch/cmp.h
create mode 100644 libnetwork/libnl3/include/netlink/route/cls/ematch/meta.h
create mode 100644 libnetwork/libnl3/include/netlink/route/cls/ematch/nbyte.h
create mode 100644 libnetwork/libnl3/include/netlink/route/cls/ematch/text.h
create mode 100644 libnetwork/libnl3/include/netlink/route/cls/fw.h
create mode 100644 libnetwork/libnl3/include/netlink/route/cls/police.h
create mode 100644 libnetwork/libnl3/include/netlink/route/cls/u32.h
create mode 100644 libnetwork/libnl3/include/netlink/route/link.h
create mode 100644 libnetwork/libnl3/include/netlink/route/link/api.h
create mode 100644 libnetwork/libnl3/include/netlink/route/link/bonding.h
create mode 100644 libnetwork/libnl3/include/netlink/route/link/inet.h
create mode 100644 libnetwork/libnl3/include/netlink/route/link/info-api.h
create mode 100644 libnetwork/libnl3/include/netlink/route/link/vlan.h
create mode 100644 libnetwork/libnl3/include/netlink/route/neighbour.h
create mode 100644 libnetwork/libnl3/include/netlink/route/neightbl.h
create mode 100644 libnetwork/libnl3/include/netlink/route/nexthop.h
create mode 100644 libnetwork/libnl3/include/netlink/route/pktloc.h
create mode 100644 libnetwork/libnl3/include/netlink/route/qdisc.h
create mode 100644 libnetwork/libnl3/include/netlink/route/qdisc/cbq.h
create mode 100644 libnetwork/libnl3/include/netlink/route/qdisc/dsmark.h
create mode 100644 libnetwork/libnl3/include/netlink/route/qdisc/fifo.h
create mode 100644 libnetwork/libnl3/include/netlink/route/qdisc/htb.h
create mode 100644 libnetwork/libnl3/include/netlink/route/qdisc/netem.h
create mode 100644 libnetwork/libnl3/include/netlink/route/qdisc/prio.h
create mode 100644 libnetwork/libnl3/include/netlink/route/qdisc/red.h
create mode 100644 libnetwork/libnl3/include/netlink/route/qdisc/sfq.h
create mode 100644 libnetwork/libnl3/include/netlink/route/qdisc/tbf.h
create mode 100644 libnetwork/libnl3/include/netlink/route/route.h
create mode 100644 libnetwork/libnl3/include/netlink/route/rtnl.h
create mode 100644 libnetwork/libnl3/include/netlink/route/rule.h
create mode 100644 libnetwork/libnl3/include/netlink/route/tc-api.h
create mode 100644 libnetwork/libnl3/include/netlink/route/tc.h
create mode 100644 libnetwork/libnl3/include/netlink/socket.h
create mode 100644 libnetwork/libnl3/include/netlink/types.h
create mode 100644 libnetwork/libnl3/include/netlink/utils.h
create mode 100644 libnetwork/libnl3/include/netlink/version.h
create mode 100644 libnetwork/libnl3/include/netlink/version.h.in
create mode 100644 libnetwork/libnl3/lib/Makefile.am
create mode 100644 libnetwork/libnl3/lib/addr.c
create mode 100644 libnetwork/libnl3/lib/attr.c
create mode 100644 libnetwork/libnl3/lib/cache.c
create mode 100644 libnetwork/libnl3/lib/cache_mngr.c
create mode 100644 libnetwork/libnl3/lib/cache_mngt.c
create mode 100644 libnetwork/libnl3/lib/cli/cls/.dirstamp
create mode 100644 libnetwork/libnl3/lib/cli/cls/basic.c
create mode 100644 libnetwork/libnl3/lib/cli/cls/cgroup.c
create mode 100644 libnetwork/libnl3/lib/cli/qdisc/.dirstamp
create mode 100644 libnetwork/libnl3/lib/cli/qdisc/bfifo.c
create mode 100644 libnetwork/libnl3/lib/cli/qdisc/blackhole.c
create mode 100644 libnetwork/libnl3/lib/cli/qdisc/htb.c
create mode 100644 libnetwork/libnl3/lib/cli/qdisc/pfifo.c
create mode 100644 libnetwork/libnl3/lib/data.c
create mode 100644 libnetwork/libnl3/lib/defs.h
create mode 100644 libnetwork/libnl3/lib/defs.h.in
create mode 100644 libnetwork/libnl3/lib/error.c
create mode 100644 libnetwork/libnl3/lib/fib_lookup/.dirstamp
create mode 100644 libnetwork/libnl3/lib/fib_lookup/lookup.c
create mode 100644 libnetwork/libnl3/lib/fib_lookup/request.c
create mode 100644 libnetwork/libnl3/lib/genl/.dirstamp
create mode 100644 libnetwork/libnl3/lib/genl/ctrl.c
create mode 100644 libnetwork/libnl3/lib/genl/family.c
create mode 100644 libnetwork/libnl3/lib/genl/genl.c
create mode 100644 libnetwork/libnl3/lib/genl/mngt.c
create mode 100644 libnetwork/libnl3/lib/handlers.c
create mode 100644 libnetwork/libnl3/lib/msg.c
create mode 100644 libnetwork/libnl3/lib/netfilter/.dirstamp
create mode 100644 libnetwork/libnl3/lib/netfilter/ct.c
create mode 100644 libnetwork/libnl3/lib/netfilter/ct_obj.c
create mode 100644 libnetwork/libnl3/lib/netfilter/log.c
create mode 100644 libnetwork/libnl3/lib/netfilter/log_msg.c
create mode 100644 libnetwork/libnl3/lib/netfilter/log_msg_obj.c
create mode 100644 libnetwork/libnl3/lib/netfilter/log_obj.c
create mode 100644 libnetwork/libnl3/lib/netfilter/netfilter.c
create mode 100644 libnetwork/libnl3/lib/netfilter/nfnl.c
create mode 100644 libnetwork/libnl3/lib/netfilter/queue.c
create mode 100644 libnetwork/libnl3/lib/netfilter/queue_msg.c
create mode 100644 libnetwork/libnl3/lib/netfilter/queue_msg_obj.c
create mode 100644 libnetwork/libnl3/lib/netfilter/queue_obj.c
create mode 100644 libnetwork/libnl3/lib/nl.c
create mode 100644 libnetwork/libnl3/lib/object.c
create mode 100644 libnetwork/libnl3/lib/route/.dirstamp
create mode 100644 libnetwork/libnl3/lib/route/addr.c
create mode 100644 libnetwork/libnl3/lib/route/class.c
create mode 100644 libnetwork/libnl3/lib/route/classid.c
create mode 100644 libnetwork/libnl3/lib/route/cls.c
create mode 100644 libnetwork/libnl3/lib/route/cls/.dirstamp
create mode 100644 libnetwork/libnl3/lib/route/cls/basic.c
create mode 100644 libnetwork/libnl3/lib/route/cls/cgroup.c
create mode 100644 libnetwork/libnl3/lib/route/cls/ematch.c
create mode 100644 libnetwork/libnl3/lib/route/cls/ematch/.dirstamp
create mode 100644 libnetwork/libnl3/lib/route/cls/ematch/cmp.c
create mode 100644 libnetwork/libnl3/lib/route/cls/ematch/container.c
create mode 100644 libnetwork/libnl3/lib/route/cls/ematch/meta.c
create mode 100644 libnetwork/libnl3/lib/route/cls/ematch/nbyte.c
create mode 100644 libnetwork/libnl3/lib/route/cls/ematch/text.c
create mode 100644 libnetwork/libnl3/lib/route/cls/ematch_grammar.l
create mode 100644 libnetwork/libnl3/lib/route/cls/ematch_syntax.y
create mode 100644 libnetwork/libnl3/lib/route/cls/fw.c
create mode 100644 libnetwork/libnl3/lib/route/cls/police.c
create mode 100644 libnetwork/libnl3/lib/route/cls/u32.c
create mode 100644 libnetwork/libnl3/lib/route/link.c
create mode 100644 libnetwork/libnl3/lib/route/link/.dirstamp
create mode 100644 libnetwork/libnl3/lib/route/link/api.c
create mode 100644 libnetwork/libnl3/lib/route/link/bonding.c
create mode 100644 libnetwork/libnl3/lib/route/link/bridge.c
create mode 100644 libnetwork/libnl3/lib/route/link/dummy.c
create mode 100644 libnetwork/libnl3/lib/route/link/inet.c
create mode 100644 libnetwork/libnl3/lib/route/link/inet6.c
create mode 100644 libnetwork/libnl3/lib/route/link/vlan.c
create mode 100644 libnetwork/libnl3/lib/route/neigh.c
create mode 100644 libnetwork/libnl3/lib/route/neightbl.c
create mode 100644 libnetwork/libnl3/lib/route/nexthop.c
create mode 100644 libnetwork/libnl3/lib/route/pktloc.c
create mode 100644 libnetwork/libnl3/lib/route/pktloc_grammar.l
create mode 100644 libnetwork/libnl3/lib/route/pktloc_syntax.y
create mode 100644 libnetwork/libnl3/lib/route/qdisc.c
create mode 100644 libnetwork/libnl3/lib/route/qdisc/.dirstamp
create mode 100644 libnetwork/libnl3/lib/route/qdisc/blackhole.c
create mode 100644 libnetwork/libnl3/lib/route/qdisc/cbq.c
create mode 100644 libnetwork/libnl3/lib/route/qdisc/dsmark.c
create mode 100644 libnetwork/libnl3/lib/route/qdisc/fifo.c
create mode 100644 libnetwork/libnl3/lib/route/qdisc/htb.c
create mode 100644 libnetwork/libnl3/lib/route/qdisc/netem.c
create mode 100644 libnetwork/libnl3/lib/route/qdisc/prio.c
create mode 100644 libnetwork/libnl3/lib/route/qdisc/red.c
create mode 100644 libnetwork/libnl3/lib/route/qdisc/sfq.c
create mode 100644 libnetwork/libnl3/lib/route/qdisc/tbf.c
create mode 100644 libnetwork/libnl3/lib/route/route.c
create mode 100644 libnetwork/libnl3/lib/route/route_obj.c
create mode 100644 libnetwork/libnl3/lib/route/route_utils.c
create mode 100644 libnetwork/libnl3/lib/route/rtnl.c
create mode 100644 libnetwork/libnl3/lib/route/rule.c
create mode 100644 libnetwork/libnl3/lib/route/tc.c
create mode 100644 libnetwork/libnl3/lib/socket.c
create mode 100644 libnetwork/libnl3/lib/stamp-h1
create mode 100644 libnetwork/libnl3/lib/utils.c
create mode 100644 libxkutil/network_model_helper.c
create mode 100644 libxkutil/network_model_helper.h
create mode 100644 schema/EthernetPort.mof
create mode 100644 schema/EthernetPort.registration
create mode 100644 schema/EthernetPortAllocationSettingData.mof
create mode 100644 schema/EthernetPortAllocationSettingData.registration
create mode 100644 schema/VirtualEthernetSwitchSystem.mof
create mode 100644 schema/VirtualEthernetSwitchSystem.registration
create mode 100644 schema/VirtualEthernetSwitchSystemSettingData.mof
create mode 100644 schema/VirtualEthernetSwitchSystemSettingData.registration
create mode 100644 src/Virt_EASD.c
create mode 100644 src/Virt_EASD.h
create mode 100644 src/Virt_EthernetPort.c
create mode 100644 src/Virt_EthernetPort.h
create mode 100644 src/Virt_VESSSD.c
create mode 100644 src/Virt_VESSSD.h
create mode 100644 src/Virt_VirtualEthernetSwitchSystem.c
create mode 100644 src/Virt_VirtualEthernetSwitchSystem.h
--
1.7.6
12 years, 7 months
[V4 PATCH 8/8] vlan library - testing program for libnetwork
by Wenchao Xia
Provide a pure C test program employing libnetwork. Note it is linked
with libcmpiutil, so need CU_DEBUG to be set to stdout to see the output.
Try vconfig and brctl command modifying the network and then run the test
program to see the output.
Signed-off-by: Wenchao Xia <xiawenc(a)cn.ibm.com>
---
libnetwork/libnetwork_test.c | 91 ++++++++++++++++++++++++++++++++++++++++++
1 files changed, 91 insertions(+), 0 deletions(-)
create mode 100644 libnetwork/libnetwork_test.c
diff --git a/libnetwork/libnetwork_test.c b/libnetwork/libnetwork_test.c
new file mode 100644
index 0000000..a611846
--- /dev/null
+++ b/libnetwork/libnetwork_test.c
@@ -0,0 +1,91 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <pthread.h>
+#include <unistd.h>
+#include <time.h>
+#include <assert.h>
+#include <sys/time.h>
+
+#include "host_network_API.h"
+
+static long print_and_ret_time_stamp(void)
+{
+ struct timeval tv;
+ long ret;
+ gettimeofday(&tv, NULL);
+ ret = tv.tv_sec*1000+ tv.tv_usec/1000;
+ printf("time is [%ld] ms.", ret);
+ return ret;
+}
+
+int main(int argc, char **argv)
+{
+ EthIfacesList ifaces_list;
+ EthIface iface_ref,iface_br,iface_vlan;
+ int comp_ret = 0;
+ int persist_flag = 1;
+ long timestart, timeend;
+ int i;
+
+
+ printf("executing the program with persist flag %d.\n", persist_flag);
+ comp_ret = 0;
+
+ eth_ifaceslist_init(&ifaces_list);
+ eth_iface_init(&iface_ref);
+ eth_iface_init(&iface_br);
+ eth_iface_init(&iface_vlan);
+
+ eth_iface_add_br_prop(&iface_br);
+ eth_iface_add_vlan_prop(&iface_vlan, VLAN_TYPE_802_1_Q);
+ iface_br.eth_type = ETH_TYPE_ETHER_SUB_BRIDGE | ETH_TYPE_ETHER_ANY;
+ iface_vlan.eth_type = ETH_TYPE_ETHER_SUB_VLAN | ETH_TYPE_ETHER_ANY;
+
+ //iface_ref.name = SAFE_STRDUP("eth1.100");
+ iface_ref.eth_type = ETH_TYPE_ETHER_SUB_BRIDGE | ETH_TYPE_ETHER_ANY;
+
+ iface_br.name = SAFE_STRDUP("test_br");
+ iface_vlan.name = SAFE_STRDUP("eth0.1000");
+
+ iface_br.pbr_prop->STP = 1;
+
+ iface_vlan.pvlan_prop->vlan_type = VLAN_TYPE_802_1_Q;
+ iface_vlan.pvlan_prop->props.prop_8021q.parent = SAFE_STRDUP("eth0");
+ iface_vlan.pvlan_prop->props.prop_8021q.vlan_id = 1000;
+ iface_vlan.pvlan_prop->props.prop_8021q.reorder_hdr = 0;
+ iface_vlan.pvlan_prop->props.prop_8021q.ingress.count = 1;
+ iface_vlan.pvlan_prop->props.prop_8021q.ingress.values[0].from = 2;
+ iface_vlan.pvlan_prop->props.prop_8021q.ingress.values[0].to = 3;
+ iface_vlan.pvlan_prop->props.prop_8021q.egress.count = 1;
+ iface_vlan.pvlan_prop->props.prop_8021q.egress.values[0].from = 4;
+ iface_vlan.pvlan_prop->props.prop_8021q.egress.values[0].to = 6;
+
+ timestart = print_and_ret_time_stamp();
+ printf(" start list the host ifaces.\n");
+
+ get_host_ifaces(&ifaces_list, NULL, NULL);
+ //get_host_ifaces(&ifaces_list, eth_iface_filter_by_ref, &iface_ref);
+ //get_host_ifaces(&ifaces_list, eth_iface_filter_vlans, NULL);
+ //get_host_ifaces(&ifaces_list, eth_iface_filter_peths, NULL);
+
+ timeend = print_and_ret_time_stamp();
+ printf(" end list the host ifaces, cost [%ld]ms.\n", timeend-timestart);
+
+ eth_ifaceslist_print(&ifaces_list);
+ eth_ifaceslist_uninit(&ifaces_list);
+
+ /* test for mem leak */
+/*
+ for (i = 0; i < 10; i++) {
+ eth_ifaceslist_init(&ifaces_list);
+ get_host_ifaces(&ifaces_list, NULL, NULL);
+ eth_ifaceslist_uninit(&ifaces_list);
+ }
+*/
+ eth_iface_uninit(&iface_ref);
+ eth_iface_uninit(&iface_br);
+ eth_iface_uninit(&iface_vlan);
+
+ return 0;
+}
--
1.7.1
12 years, 7 months
[V4 PATCH 7/8] vlan library - add interface for CIM model code
by Wenchao Xia
This patch simple add APIs.
Signed-off-by: Wenchao Xia <xiawenc(a)cn.ibm.com>
---
libnetwork/host_network_API.c | 30 ++++++++++++++++++++++++++++++
libnetwork/host_network_API.h | 25 +++++++++++++++++++++++++
2 files changed, 55 insertions(+), 0 deletions(-)
create mode 100644 libnetwork/host_network_API.c
create mode 100644 libnetwork/host_network_API.h
diff --git a/libnetwork/host_network_API.c b/libnetwork/host_network_API.c
new file mode 100644
index 0000000..975dbda
--- /dev/null
+++ b/libnetwork/host_network_API.c
@@ -0,0 +1,30 @@
+/*
+ * Copyright IBM Corp. 2012
+ *
+ * Authors:
+ * Wenchao Xia <xiawenc(a)cn.ibm.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ */
+
+
+#include "host_network_API.h"
+#include "host_network_implement_OSAPI.h"
+#include "host_network_error.h"
+
+/* this layer is added to devide the abstraction and implemention, so that
+ different implemention could be used and switched */
+
+int get_host_ifaces(EthIfacesList *plist,
+ eth_iface_filter_func filter_func, void *filter_opaque)
+{
+ return get_host_eth_ifaces_osapi(plist, filter_func, filter_opaque);
+}
+
+char *get_host_iface_error_reason(int errno)
+{
+ return translate_error_no(errno);
+}
diff --git a/libnetwork/host_network_API.h b/libnetwork/host_network_API.h
new file mode 100644
index 0000000..e3732a4
--- /dev/null
+++ b/libnetwork/host_network_API.h
@@ -0,0 +1,25 @@
+/*
+ * Copyright IBM Corp. 2012
+ *
+ * Authors:
+ * Wenchao Xia <xiawenc(a)cn.ibm.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ */
+
+#ifndef HOST_NETWORK_API
+#define HOST_NETWORK_API
+
+#include "dll_magic.h"
+#include "host_network_basic.h"
+#include "host_network_helper.h"
+
+DLL_PUBLIC int get_host_ifaces(EthIfacesList *plist,
+ eth_iface_filter_func filter_func, void *filter_opaque);
+
+DLL_PUBLIC char *get_host_iface_error_reason(int errno);
+
+#endif
--
1.7.1
12 years, 7 months
[V4 PATCH 6/8] vlan library - add help functions and error defines
by Wenchao Xia
This patch have help functions for libnetwork. It contains macro defines
and help functions for host network configuration. It also provide some basic
function such as conditional merge char*, int and properties of structure
EthIface.
Signed-off-by: Wenchao Xia <xiawenc(a)cn.ibm.com>
---
libnetwork/dll_magic.h | 13 ++
libnetwork/host_network_error.h | 23 ++++
libnetwork/host_network_helper.c | 266 ++++++++++++++++++++++++++++++++++++++
libnetwork/host_network_helper.h | 177 +++++++++++++++++++++++++
4 files changed, 479 insertions(+), 0 deletions(-)
create mode 100644 libnetwork/dll_magic.h
create mode 100644 libnetwork/host_network_error.h
create mode 100644 libnetwork/host_network_helper.c
create mode 100644 libnetwork/host_network_helper.h
diff --git a/libnetwork/dll_magic.h b/libnetwork/dll_magic.h
new file mode 100644
index 0000000..36bca83
--- /dev/null
+++ b/libnetwork/dll_magic.h
@@ -0,0 +1,13 @@
+#ifndef DLL_MAGIC_H
+#define DLL_MAGIC_H
+
+
+#if __GNUC__ >= 4
+ #ifdef DLL_BUILD
+ #define DLL_PUBLIC __attribute__ ((visibility ("default")))
+ #else
+ #define DLL_PUBLIC
+ #endif
+#endif
+
+#endif
diff --git a/libnetwork/host_network_error.h b/libnetwork/host_network_error.h
new file mode 100644
index 0000000..1882172
--- /dev/null
+++ b/libnetwork/host_network_error.h
@@ -0,0 +1,23 @@
+#ifndef HOST_NETWORK_ERROR_H
+#define HOST_NETWORK_ERROR_H
+
+#define ERR_REQUEST_NOT_SUPPORT -1
+
+#define ERR_LIBNETLINK -80
+#define ERR_LIBBR -90
+
+#define ERR_DEVICE_EXCEED_MAXNUM -100
+#define ERR_DEVICE_EXIST -101
+#define ERR_DEVICE_NOT_EXIST -102
+#define ERR_DEVICE_ALREADY_DONE -103
+#define ERR_DEVICE_CONNECT_OTHER -104
+
+#define ERR_FILE_OP_FAIL -125
+#define ERR_FILE_EMPTY -126
+#define ERR_FILE_TOO_LARGE -127
+#define ERR_FILE_CONT_TOO_LARGE -128
+#define ERR_FILE_LOCK_FAIL -129
+
+#define ERR_PERSIST_NOT_REDHAT -200
+
+#endif
diff --git a/libnetwork/host_network_helper.c b/libnetwork/host_network_helper.c
new file mode 100644
index 0000000..cda2732
--- /dev/null
+++ b/libnetwork/host_network_helper.c
@@ -0,0 +1,266 @@
+/*
+ * Copyright IBM Corp. 2012
+ *
+ * Authors:
+ * Wenchao Xia <xiawenc(a)cn.ibm.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ */
+
+
+
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/socket.h>
+#include <linux/if.h>
+
+#include "host_network_helper.h"
+#include "host_network_error.h"
+
+static int compare_qos_8021q(const void *p1, const void *p2)
+{
+ const VLAN_Qos_8021q_elem *qos1 = (VLAN_Qos_8021q_elem *)p1;
+ const VLAN_Qos_8021q_elem *qos2 = (VLAN_Qos_8021q_elem *)p2;
+ int ret = 0;
+ if ((qos1->from) > (qos2->from)) {
+ ret = 1;
+ }
+ return ret;
+}
+
+/* it need to be checked see whether these are the conditions */
+int vlan_8021q_qos_check_valid(VLAN_Qos_8021q *pqos)
+{
+ int ret = 1;
+ int i = 0;
+ int last_num = -1;
+ if ((pqos->count < 0) || (pqos->count > 8)) {
+ ret = 0;
+ goto out;
+ } else if (pqos->count == 0) {
+ goto out;
+ }
+ qsort((void *)pqos->values, pqos->count, sizeof(VLAN_Qos_8021q_elem),
+ compare_qos_8021q);
+
+ while (i < pqos->count) {
+ if (pqos->values[i].from == last_num) {
+ CU_DEBUG("error: vlan 802.1.q qos setting have same <from> values: "
+ "last is %d, new is %d", last_num, pqos->values[i].from);
+ ret = 0;
+ goto out;
+ }
+ last_num = pqos->values[i].from;
+ if ((pqos->values[i].from < 0) || (pqos->values[i].from >= 8)) {
+ CU_DEBUG("error: vlan 802.1.q qos setting have outbound value: "
+ "from is %d.", pqos->values[i].from);
+ ret = 0;
+ goto out;
+ }
+ if ((pqos->values[i].to < 0) || (pqos->values[i].to >= 8)) {
+ CU_DEBUG("error: vlan 802.1.q qos setting have outbound value: "
+ "to is %d.", pqos->values[i].to);
+ ret = 0;
+ goto out;
+ }
+ i++;
+ }
+
+ out:
+ return ret;
+}
+
+int vlan_8021q_qos_str_to_num(VLAN_Qos_8021q *pqos, const char* str)
+{
+ int ret = 1;
+ char *str_line = NULL;
+ char *temp;
+ char *saveptr = NULL;
+ char *invalptr1, *invalptr2;
+ int qos_num1, qos_num2;
+ VLAN_Qos_8021q qos;
+
+ if (str == NULL) {
+ ret = 0;
+ goto out;
+ }
+ if (str[0] == '\0') {
+ ret = 1;
+ pqos->count = 0;
+ CU_DEBUG("empty vlan 802.1.q qos string found.");
+ goto out;
+ }
+ str_line = SAFE_STRDUP(str);
+ qos.count = 0;
+
+ temp = strtok_r(str_line, " ", &saveptr);
+ while (temp != NULL) {
+ qos_num1 = strtol(temp, &invalptr1, 10);
+ if (temp == invalptr1) {
+ ret = 0;
+ goto out;
+ }
+ if (*invalptr1 != ':') {
+ ret = 0;
+ goto out;
+ }
+ invalptr1++;
+ qos_num2 = strtol(invalptr1, &invalptr2, 10);
+ if (invalptr1 == invalptr2) {
+ ret = 0;
+ goto out;
+ }
+ if (*invalptr2 != '\0') {
+ ret = 0;
+ goto out;
+ }
+ if (qos.count >= 8) {
+ ret = 0;
+ CU_DEBUG("too many settings found in vlan 802.1.q qos string [%s]",
+ str);
+ goto out;
+ }
+ qos.values[qos.count].from = qos_num1;
+ qos.values[qos.count].to = qos_num2;
+ qos.count++;
+ temp = strtok_r(NULL, " ", &saveptr);
+ }
+ ret = vlan_8021q_qos_check_valid(&qos);
+ if (ret == 1) {
+ *pqos = qos;
+ }
+
+ out:
+ if (ret != 1) {
+ CU_DEBUG("vlan 802.1.q qos string [%s] is invalid.", str);
+ }
+ SAFE_FREE(str_line);
+ return ret;
+}
+
+int vlan_8021q_qos_num_to_str(char **str, const VLAN_Qos_8021q *pqos)
+{
+ char temp[16];
+ int i;
+ VLAN_Qos_8021q qos = *pqos;
+ int ret = vlan_8021q_qos_check_valid(&qos);
+ if (ret != 1) {
+ goto out;
+ }
+ SAFE_MALLOC(*str, 64);
+ *str[0] = '\0';
+ if (qos.count == 0) {
+ goto out;
+ }
+ i = 0;
+ snprintf(temp, sizeof(temp), "%d:%d",
+ qos.values[i].from, qos.values[i].to);
+ strcat(*str, temp);
+ i++;
+ while (i < qos.count) {
+ strcat(*str, " ");
+ snprintf(temp, sizeof(temp), "%d:%d",
+ qos.values[i].from, qos.values[i].to);
+ strcat(*str, temp);
+ i++;
+ }
+
+ out:
+ return ret;
+}
+
+char *combine_file_name(const char *prefix, const char *name)
+{
+ char *ret = NULL;
+ int size;
+ size = strlen(prefix) + strlen(name) + 1;
+ SAFE_CALLOC(ret, size, sizeof(char));
+ snprintf(ret, size, "%s%s", prefix, name);
+ return ret;
+}
+
+char *translate_error_no(int errno)
+{
+ char *ret = NULL;
+ switch (errno) {
+ case ERR_REQUEST_NOT_SUPPORT:
+ ret = "request is not supported now";
+ break;
+
+ case ERR_LIBNETLINK:
+ ret = "error happend in netlink.";
+ break;
+ case ERR_LIBBR:
+ ret = "error happend in bridge commands.";
+ break;
+
+ case ERR_DEVICE_EXCEED_MAXNUM:
+ ret = "too many devices found or set, check the environment.";
+ break;
+ case ERR_DEVICE_EXIST:
+ ret = "device already exist, can not execute the command.";
+ break;
+ case ERR_DEVICE_NOT_EXIST:
+ ret = "device do not exist, can not execute the command.";
+ break;
+ case ERR_DEVICE_ALREADY_DONE:
+ ret = "the operation you want have been done before, "
+ "will not do it again.";
+ break;
+ case ERR_DEVICE_CONNECT_OTHER:
+ ret = "the device you want to connect have been connect to another"
+ " device, can't change it directly.";
+ break;
+
+ case ERR_FILE_OP_FAIL:
+ ret = "failed in accessing the file.";
+ break;
+ case ERR_FILE_EMPTY:
+ ret = "the file it want is empty.";
+ break;
+ case ERR_FILE_TOO_LARGE:
+ ret = "the file it want is too large.";
+ break;
+ case ERR_FILE_CONT_TOO_LARGE:
+ ret = "the content it want to combine to file is too large.";
+ break;
+ case ERR_FILE_LOCK_FAIL:
+ ret = "failed in locking the file, "
+ "check if other process is using it.";
+ break;
+
+ case ERR_PERSIST_NOT_REDHAT:
+ ret = "host is not a RedHat distribution, can't persist the "
+ "configuration, it would not take effect after host is "
+ "rebooted. Other version would be supported in the future. "
+ "If you are sure host is RedHat, make sure command "
+ "<lsb_release -a> could work.";
+ break;
+
+ default:
+ ret = "internal error.";
+ break;
+ }
+ return ret;
+}
+
+int get_simple_state(struct EthIface *piface)
+{
+ if ((piface->eth_type & ETH_TYPE_ETHER_ANY) &&
+ (piface->eth_type & ETH_TYPE_ETHER_SUB_BRIDGE)) {
+ if (piface->run_prop.status == IF_OPER_UNKNOWN) {
+ return 1;
+ }
+ }
+ if (piface->run_prop.status == IF_OPER_UP) {
+ return 1;
+ } else {
+ return 0;
+ }
+}
diff --git a/libnetwork/host_network_helper.h b/libnetwork/host_network_helper.h
new file mode 100644
index 0000000..fea4f05
--- /dev/null
+++ b/libnetwork/host_network_helper.h
@@ -0,0 +1,177 @@
+/*
+ * Copyright IBM Corp. 2012
+ *
+ * Authors:
+ * Wenchao Xia <xiawenc(a)cn.ibm.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ */
+
+
+#ifndef HOST_NETWORK_HELPER_H
+#define HOST_NETWORK_HELPER_H
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <arpa/inet.h>
+
+#include "dll_magic.h"
+#include "host_network_basic.h"
+
+#ifdef TESTLIB
+#include "TestDefines.h"
+#else
+#include <libcmpiutil/libcmpiutil.h>
+#endif
+
+#define CMD_DEBUG_LEVEL 2
+
+/* macro functions */
+#define CMD_DEBUG(lvl, fmt, args...) do { \
+ if (CMD_DEBUG_LEVEL && (lvl) <= CMD_DEBUG_LEVEL) { \
+ debug_print(fmt, ##args); \
+ } \
+} while (0)
+
+#define SAFE_MALLOC(p, size) \
+{ \
+ (p) = malloc((size)); \
+ if ((p) == NULL) { \
+ CU_DEBUG("malloc failed."); \
+ } \
+}
+
+#define SAFE_CALLOC(p, nmen, size) \
+{ \
+ (p) = calloc((nmen), (size)); \
+ if ((p) == NULL) { \
+ CU_DEBUG("calloc failed."); \
+ } \
+}
+
+#define SAFE_FREE(p) {free(p); (p) = NULL; }
+
+
+/* Macro used to compare two char*, it would skip if ref is NULL. It would
+ only set the result when src != ref, user need to set the result to 1 by
+ default before use the macro. If not set, the it could be used to do
+ check multi times in "one fail all die" mode. Empty lines is the place
+ where result should be set to 1. */
+#define CHARS_COMPARE_BY_REF(src, ref, result) do { \
+ if ((ref) == NULL) { \
+ ; \
+ } else { \
+ if ((src) == NULL) { \
+ (result) = 0; \
+ } else { \
+ if (0 == strcmp((src), (ref))) { \
+ ; \
+ } else { \
+ (result) = 0; \
+ } \
+ } \
+ } \
+} while (0)
+
+/* ignore case version */
+#define CHARS_COMPARE_CASE_BY_REF(src, ref, result) do { \
+ if ((ref) == NULL) { \
+ ; \
+ } else { \
+ if ((src) == NULL) { \
+ (result) = 0; \
+ } else { \
+ if (0 == strcasecmp((src), (ref))) { \
+ ; \
+ } else { \
+ (result) = 0; \
+ } \
+ } \
+ } \
+} while (0)
+
+/* compare the value if ref != default */
+#define NUM_COMPARE_BY_REF(src, ref, result, default) do { \
+ if ((ref) == (default)) { \
+ ; \
+ } else { \
+ if ((src) == (ref)) { \
+ ; \
+ } else { \
+ result = 0; \
+ } \
+ } \
+} while (0)
+
+/* merge the char* string to dest, only when dest == NULL */
+#define CHARS_MERGE_NORMAL(dest, src) do { \
+ if (((dest) == NULL) && ((src) != NULL)) { \
+ (dest) = strdup((src)); \
+ } \
+} while (0)
+
+/* merge the char* string to dest, only when dest == NULL,
+ pointer is moved instead of strdup */
+#define CHARS_MERGE_MOVE(dest, src) do { \
+ if (((dest) == NULL) && ((src) != NULL)) { \
+ (dest) = (src); \
+ (src) = NULL; \
+ } \
+} while (0)
+
+/* merge the value, only when dest == default */
+#define NUM_MERGE(dest, src, default) do { \
+ if ((dest) == (default)) { \
+ (dest) = (src); \
+ } \
+} while (0)
+
+/* this macro may cause "p" to be excuted twice if it is a function */
+#define SAFE_STRDUP(p) (p) == NULL ? NULL : strdup(p);
+
+/* this macro make sure "src" to be excuted once if it is function, so it is
+ safe for functions that have state logged, such as "strtok" */
+#define SAFE_STRDUP_WITH_FUNC(dest, src, iter) do { \
+ (iter) = (src); \
+ if ((iter) == NULL) { \
+ (dest) = NULL; \
+ } else { \
+ (dest) = strdup((iter)); \
+ } \
+} while (0)
+
+/* array version of SAFE_STRDUP, dest and src are char**. */
+#define SAFE_PSTR_ARRAY_DUP(ppdest, dest_num, ppsrc, src_num, iter) do { \
+ (dest_num) = (src_num); \
+ (ppdest) = NULL; \
+ if (((ppsrc) != NULL) && ((src_num) > 0)) { \
+ SAFE_CALLOC((ppdest), (src_num), sizeof(char *)); \
+ (iter) = 0; \
+ while ((iter) < (src_num)) { \
+ *((ppdest)+(iter)) = SAFE_STRDUP(*((ppsrc)+(iter))); \
+ (iter)++; \
+ } \
+ } \
+} while (0)
+
+/* this function would sort the pqos and check its values. */
+int vlan_8021q_qos_check_valid(VLAN_Qos_8021q *pqos);
+
+/* converting qos string of 802.1.Q, it should be as "0:0 1:0 2:0" */
+DLL_PUBLIC int vlan_8021q_qos_str_to_num(VLAN_Qos_8021q *pqos, const char *str);
+DLL_PUBLIC int vlan_8021q_qos_num_to_str(char **str, const VLAN_Qos_8021q *pqos);
+
+/* following functions would return string by malloc, so it need free later */
+char *combine_file_name(const char *prefix, const char *name);
+
+/* translate the iffstate to simple down or up, because orginal state is
+ complex for history reason in linux kernel */
+DLL_PUBLIC int get_simple_state(struct EthIface *piface);
+
+/* err message number to char* */
+char *translate_error_no(int errno);
+
+#endif
--
1.7.1
12 years, 7 months
[V4 PATCH 5/8] vlan library - add basic structure and related functions
by Wenchao Xia
this patch have the structure defines and related functions, make program
in upper level easy to use.
Signed-off-by: Wenchao Xia <xiawenc(a)cn.ibm.com>
---
libnetwork/host_network_basic.c | 656 +++++++++++++++++++++++++++++++++++++++
libnetwork/host_network_basic.h | 158 ++++++++++
2 files changed, 814 insertions(+), 0 deletions(-)
create mode 100644 libnetwork/host_network_basic.c
create mode 100644 libnetwork/host_network_basic.h
diff --git a/libnetwork/host_network_basic.c b/libnetwork/host_network_basic.c
new file mode 100644
index 0000000..9260b33
--- /dev/null
+++ b/libnetwork/host_network_basic.c
@@ -0,0 +1,656 @@
+/*
+ * Copyright IBM Corp. 2012
+ *
+ * Authors:
+ * Wenchao Xia <xiawenc(a)cn.ibm.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ */
+
+#include "host_network_basic.h"
+#include "host_network_helper.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+static void vlan_prop_print(VLAN_Prop *pvlan_prop)
+{
+ VLAN_Prop_8021q *p_8021q;
+ char *ingress = NULL, *egress = NULL;
+ CMD_DEBUG(1, "--VLAN props: type %d.\n",
+ pvlan_prop->vlan_type);
+ if (pvlan_prop->vlan_type == VLAN_TYPE_802_1_Q) {
+ p_8021q = &(pvlan_prop->props.prop_8021q);
+ vlan_8021q_qos_num_to_str(&ingress, &(p_8021q->ingress));
+ vlan_8021q_qos_num_to_str(&egress, &(p_8021q->egress));
+ CMD_DEBUG(1, "----IEEE802.1.Q: id %d, reorder %d, priority %d, "
+ "ingress %s, egress %s, parent %s.\n",
+ p_8021q->vlan_id, p_8021q->reorder_hdr, p_8021q->priv_flag,
+ ingress, egress, p_8021q->parent);
+ }
+ SAFE_FREE(ingress);
+ SAFE_FREE(egress);
+}
+
+static void br_prop_print(BR_Prop *pbr_prop)
+{
+ int i = 0;
+ CMD_DEBUG(1, "--Bridge props: id %s, stp %d, "
+ "bridge type %d, port_num %d.\n",
+ pbr_prop->bridge_id, pbr_prop->STP,
+ pbr_prop->type, pbr_prop->port_num);
+ if (pbr_prop->port_names != NULL) {
+ CMD_DEBUG(1, "----Ports attached: ");
+ while (i < pbr_prop->port_num) {
+ CMD_DEBUG(1, " %s,", *(pbr_prop->port_names+i));
+ i++;
+ }
+ CMD_DEBUG(1, "\n");
+ }
+}
+
+void eth_iface_print(EthIface *piface)
+{
+ CMD_DEBUG(1, "Iface device: name %s.\n"
+ "--Main Props: parent %s, attach to %s, mac %s,"
+ " RX %lld, TX %lld, status %d, iface type 0x%x.\n",
+ piface->name, piface->dep_ifname, piface->attach_bridge,
+ piface->mac,
+ piface->run_prop.rx_bytes, piface->run_prop.tx_bytes,
+ piface->run_prop.status, piface->eth_type);
+ if (piface->pbr_prop != NULL) {
+ br_prop_print(piface->pbr_prop);
+ }
+ if (piface->pvlan_prop != NULL) {
+ vlan_prop_print(piface->pvlan_prop);
+ }
+ return;
+}
+
+void eth_ifaceslist_print(EthIfacesList *plist)
+{
+ int i = 0;
+ CMD_DEBUG(1, "Have %d ifaces in the list:\n", plist->count);
+ while (i < plist->count) {
+ CMD_DEBUG(1, "%04d ", i);
+ eth_iface_print(plist->pifaces[i]);
+ i++;
+ }
+}
+
+void vlan_prop_init(VLAN_Prop *pvlan_prop, int vlan_type)
+{
+ VLAN_Prop_8021q *p_8021q;
+ memset(pvlan_prop, 0, sizeof(VLAN_Prop));
+ pvlan_prop->vlan_type = vlan_type;
+ if (pvlan_prop->vlan_type == VLAN_TYPE_802_1_Q) {
+ p_8021q = &(pvlan_prop->props.prop_8021q);
+ p_8021q->ingress.count = NUM_NOT_GOT;
+ p_8021q->egress.count = NUM_NOT_GOT;
+ p_8021q->vlan_id = NUM_NOT_GOT;
+ p_8021q->reorder_hdr = NUM_NOT_GOT;
+ p_8021q->priv_flag = NUM_NOT_GOT;
+ }
+}
+
+void br_prop_init(BR_Prop *pbr_prop)
+{
+ memset(pbr_prop, 0, sizeof(BR_Prop));
+ pbr_prop->STP = NUM_NOT_GOT;
+ pbr_prop->type = BR_TYPE_NOT_GOT;
+ pbr_prop->port_num = NUM_NOT_GOT;
+}
+
+void eth_iface_init(EthIface *piface)
+{
+ memset(piface, 0, sizeof(EthIface));
+ piface->eth_type = ETH_TYPE_NOT_GOT;
+ piface->run_prop.rx_bytes = NUM_NOT_GOT;
+ piface->run_prop.tx_bytes = NUM_NOT_GOT;
+ piface->run_prop.status = NUM_NOT_GOT;
+ return;
+}
+
+void eth_iface_add_br_prop(EthIface *piface)
+{
+ SAFE_MALLOC(piface->pbr_prop, sizeof(BR_Prop));
+ br_prop_init(piface->pbr_prop);
+}
+
+void eth_iface_add_vlan_prop(EthIface *piface, int vlan_type)
+{
+ SAFE_MALLOC(piface->pvlan_prop, sizeof(VLAN_Prop));
+ vlan_prop_init(piface->pvlan_prop, vlan_type);
+}
+
+void vlan_prop_uninit(VLAN_Prop *pvlan_prop)
+{
+ VLAN_Prop_8021q *p_8021q;
+ if (pvlan_prop == NULL) {
+ return;
+ }
+ if (pvlan_prop->vlan_type == VLAN_TYPE_802_1_Q) {
+ p_8021q = &(pvlan_prop->props.prop_8021q);
+ SAFE_FREE(p_8021q->parent);
+ }
+}
+
+void br_prop_uninit(BR_Prop *pbr_prop)
+{
+ int i;
+ if (pbr_prop == NULL) {
+ return;
+ }
+ SAFE_FREE(pbr_prop->bridge_id);
+ i = 0;
+ if (pbr_prop->port_names != NULL) {
+ while (i < pbr_prop->port_num) {
+ SAFE_FREE(pbr_prop->port_names[i]);
+ i++;
+ }
+ SAFE_FREE(pbr_prop->port_names);
+ }
+}
+
+void eth_iface_uninit(EthIface *piface)
+{
+ if (piface == NULL) {
+ return;
+ }
+ SAFE_FREE(piface->name);
+ SAFE_FREE(piface->dep_ifname);
+ SAFE_FREE(piface->attach_bridge);
+ SAFE_FREE(piface->mac);
+ br_prop_uninit(piface->pbr_prop);
+ SAFE_FREE(piface->pbr_prop);
+ vlan_prop_uninit(piface->pvlan_prop);
+ SAFE_FREE(piface->pvlan_prop);
+ return;
+}
+
+void eth_ifaces_clear(EthIface **ppifaces, int num)
+{
+ EthIface **t;
+ int i;
+ if (num <= 0) {
+ return;
+ }
+ t = ppifaces;
+ i = 0;
+ while (i < num) {
+ if (*t != NULL) {
+ eth_iface_uninit(*t);
+ SAFE_FREE(*t);
+ }
+ t++;
+ i++;
+ }
+ return;
+}
+
+void eth_ifaceslist_init(EthIfacesList *plist)
+{
+ plist->count = 0;
+}
+
+void eth_ifaceslist_uninit(EthIfacesList *plist)
+{
+ eth_ifaces_clear(plist->pifaces, plist->count);
+}
+
+int eth_ifaceslist_add(EthIfacesList *plist, EthIface *piface)
+{
+ if (plist->count >= MAX_IFACE_NUM) {
+ CU_DEBUG("too much device found.");
+ return 0;
+ }
+ SAFE_MALLOC(plist->pifaces[plist->count], sizeof(EthIface));
+ eth_iface_dup(plist->pifaces[plist->count], piface);
+ plist->count++;
+ return 1;
+}
+
+static void vlan_prop_dup(VLAN_Prop *dest, const VLAN_Prop *src)
+{
+ VLAN_Prop_8021q *pd_8021q;
+ const VLAN_Prop_8021q *ps_8021q;
+ dest->vlan_type = src->vlan_type;
+ if (dest->vlan_type == VLAN_TYPE_802_1_Q) {
+ pd_8021q = &(dest->props.prop_8021q);
+ ps_8021q = &(src->props.prop_8021q);
+ pd_8021q->vlan_id = ps_8021q->vlan_id;
+ pd_8021q->reorder_hdr = ps_8021q->reorder_hdr;
+ pd_8021q->priv_flag = ps_8021q->priv_flag;
+ pd_8021q->ingress = ps_8021q->ingress;
+ pd_8021q->egress = ps_8021q->egress;
+ pd_8021q->parent = SAFE_STRDUP(ps_8021q->parent);
+ }
+}
+
+static void br_prop_dup(BR_Prop *dest, const BR_Prop *src)
+{
+ int i;
+ dest->bridge_id = SAFE_STRDUP(src->bridge_id);
+ dest->STP = src->STP;
+ dest->type = src->type;
+ SAFE_PSTR_ARRAY_DUP(dest->port_names, dest->port_num,
+ src->port_names, src->port_num, i);
+}
+
+void eth_iface_dup(EthIface *dest, const EthIface *src)
+{
+ dest->name = SAFE_STRDUP(src->name);
+ dest->dep_ifname = SAFE_STRDUP(src->dep_ifname);
+ dest->attach_bridge = SAFE_STRDUP(src->attach_bridge);
+ dest->mac = SAFE_STRDUP(src->mac);
+ dest->eth_type = src->eth_type;
+ dest->run_prop.rx_bytes = src->run_prop.rx_bytes;
+ dest->run_prop.tx_bytes = src->run_prop.tx_bytes;
+ dest->run_prop.status = src->run_prop.status;
+
+ if (src->pbr_prop != NULL) {
+ SAFE_MALLOC(dest->pbr_prop, sizeof(BR_Prop));
+ /* doesn't need init it for that it would be copied at once */
+ br_prop_dup(dest->pbr_prop, src->pbr_prop);
+ } else {
+ dest->pbr_prop = NULL;
+ }
+
+ if (src->pvlan_prop != NULL) {
+ SAFE_MALLOC(dest->pvlan_prop, sizeof(VLAN_Prop));
+ /* doesn't need init it for that it would be copied at once */
+ vlan_prop_dup(dest->pvlan_prop, src->pvlan_prop);
+ } else {
+ dest->pvlan_prop = NULL;
+ }
+
+}
+
+int eth_iface_compare(const EthIface *p1, const EthIface *p2)
+{
+ int ret = 0;
+ if ((p1->name != NULL) || (p2->name != NULL)) {
+ if (0 == strcmp(p1->name, p2->name)) {
+ ret = 1;
+ }
+ }
+ return ret;
+}
+
+static void vlan_prop_merge(VLAN_Prop *pdest, VLAN_Prop *psrc, int style)
+{
+ VLAN_Prop_8021q *pd_8021q, *ps_8021q;
+
+ NUM_MERGE(pdest->vlan_type, psrc->vlan_type, VLAN_TYPE_NOT_GOT);
+
+ if (psrc->vlan_type == VLAN_TYPE_802_1_Q) {
+ pd_8021q = &(pdest->props.prop_8021q);
+ ps_8021q = &(psrc->props.prop_8021q);
+ NUM_MERGE(pd_8021q->vlan_id, ps_8021q->vlan_id, NUM_NOT_GOT);
+ NUM_MERGE(pd_8021q->reorder_hdr, ps_8021q->reorder_hdr, NUM_NOT_GOT);
+ NUM_MERGE(pd_8021q->priv_flag, ps_8021q->priv_flag, NUM_NOT_GOT);
+ if (pd_8021q->ingress.count == NUM_NOT_GOT) {
+ pd_8021q->ingress = ps_8021q->ingress;
+ }
+ if (pd_8021q->egress.count == NUM_NOT_GOT) {
+ pd_8021q->egress = ps_8021q->egress;
+ }
+ if (style == 0) {
+ CHARS_MERGE_NORMAL(pd_8021q->parent, ps_8021q->parent);
+ } else {
+ CHARS_MERGE_MOVE(pd_8021q->parent, ps_8021q->parent);
+ }
+ }
+}
+
+static void br_prop_merge(BR_Prop *pdest, BR_Prop *psrc, int style)
+{
+ int i;
+
+ if (style == 0) {
+ CHARS_MERGE_NORMAL(pdest->bridge_id, psrc->bridge_id);
+ /*merge it when dest have not been set */
+ if (pdest->port_names == NULL) {
+ SAFE_PSTR_ARRAY_DUP(pdest->port_names, pdest->port_num,
+ psrc->port_names, psrc->port_num, i);
+ }
+ } else {
+ CHARS_MERGE_MOVE(pdest->bridge_id, psrc->bridge_id);
+ /*merge it when dest have not been set */
+ if (pdest->port_names == NULL) {
+ pdest->port_names = psrc->port_names;
+ pdest->port_num = psrc->port_num;
+ psrc->port_names = NULL;
+ psrc->port_num = NUM_NOT_GOT;
+ }
+ }
+ NUM_MERGE(pdest->STP, psrc->STP, NUM_NOT_GOT);
+ NUM_MERGE(pdest->type, psrc->type, BR_TYPE_NOT_GOT);
+}
+
+void eth_iface_merge(EthIface *dest, EthIface *src, int style)
+{
+ if (style == 0) {
+ CHARS_MERGE_NORMAL(dest->name, src->name);
+ CHARS_MERGE_NORMAL(dest->dep_ifname, src->dep_ifname);
+ CHARS_MERGE_NORMAL(dest->attach_bridge, src->attach_bridge);
+ CHARS_MERGE_NORMAL(dest->mac, src->mac);
+ } else {
+ CHARS_MERGE_MOVE(dest->name, src->name);
+ CHARS_MERGE_MOVE(dest->dep_ifname, src->dep_ifname);
+ CHARS_MERGE_MOVE(dest->attach_bridge, src->attach_bridge);
+ CHARS_MERGE_MOVE(dest->mac, src->mac);
+ }
+
+ /* special case for eth_type*/
+ if (dest->eth_type == ETH_TYPE_NOT_GOT) {
+ dest->eth_type = src->eth_type;
+ } else {
+ if ((src->eth_type & ETH_TYPE_ETHER_ANY) &&
+ (dest->eth_type & ETH_TYPE_ETHER_ANY)) {
+ dest->eth_type |= (src->eth_type & ETH_TYPE_SUB_MASK);
+ }
+ }
+
+ NUM_MERGE(dest->run_prop.rx_bytes, src->run_prop.rx_bytes,
+ NUM_NOT_GOT);
+ NUM_MERGE(dest->run_prop.tx_bytes, src->run_prop.tx_bytes,
+ NUM_NOT_GOT);
+ NUM_MERGE(dest->run_prop.status, src->run_prop.status, NUM_NOT_GOT);
+
+ if (src->pbr_prop != NULL) {
+ if (dest->pbr_prop == NULL) {
+ SAFE_MALLOC(dest->pbr_prop, sizeof(BR_Prop));
+ br_prop_init(dest->pbr_prop);
+ }
+ br_prop_merge(dest->pbr_prop, src->pbr_prop, style);
+ }
+
+ if (src->pvlan_prop != NULL) {
+ if (dest->pvlan_prop == NULL) {
+ SAFE_MALLOC(dest->pvlan_prop, sizeof(VLAN_Prop));
+ vlan_prop_init(dest->pvlan_prop, src->pvlan_prop->vlan_type);
+ }
+ vlan_prop_merge(dest->pvlan_prop, src->pvlan_prop, style);
+ }
+
+}
+
+/* compare qos values */
+static int VLAN_Qos_8021q_compare_by_ref(const VLAN_Qos_8021q *pqos,
+ const VLAN_Qos_8021q *pref)
+{
+ int ret = 1;
+ int i, j;
+ if (pref->count == NUM_NOT_GOT) {
+ /* do not need to compare*/
+ goto out;
+ }
+ if ((pref->count < 0) || (pref->count > 8)) {
+ ret = 0;
+ goto out;
+ }
+ if ((pqos->count < 0) || (pqos->count > 8)) {
+ ret = 0;
+ goto out;
+ }
+
+ i = 0;
+ while (i < pref->count) {
+ j = 0;
+ while (j < pqos->count) {
+ if (pref->values[i].from == pqos->values[j].from) {
+ if (pref->values[i].to != pqos->values[j].to) {
+ ret = 0;
+ goto out;
+ }
+ break;
+ }
+ j++;
+ }
+ if (j == pqos->count) {
+ ret = 0;
+ goto out;
+ }
+ i++;
+ }
+
+ out:
+ return ret;
+}
+
+static int vlan_prop_filter_by_ref(const VLAN_Prop *pvlan_prop, void *pref)
+{
+ int compare_result = 1;
+ VLAN_Prop *ref = (VLAN_Prop *)pref;
+ char *p1, *p2;
+ const VLAN_Prop_8021q *pd_8021q;
+ VLAN_Prop_8021q *pref_8021q;
+
+ NUM_COMPARE_BY_REF(pvlan_prop->vlan_type, ref->vlan_type,
+ compare_result, VLAN_TYPE_NOT_GOT);
+ if (compare_result == 0) {
+ goto out;
+ }
+
+ if (ref->vlan_type == VLAN_TYPE_802_1_Q) {
+ pd_8021q = &(pvlan_prop->props.prop_8021q);
+ pref_8021q = &(ref->props.prop_8021q);
+
+ NUM_COMPARE_BY_REF(pd_8021q->vlan_id, pref_8021q->vlan_id,
+ compare_result, NUM_NOT_GOT);
+ if (compare_result == 0) {
+ goto out;
+ }
+
+ NUM_COMPARE_BY_REF(pd_8021q->reorder_hdr, pref_8021q->reorder_hdr,
+ compare_result, NUM_NOT_GOT);
+ if (compare_result == 0) {
+ goto out;
+ }
+
+ NUM_COMPARE_BY_REF(pd_8021q->priv_flag, pref_8021q->priv_flag,
+ compare_result, NUM_NOT_GOT);
+ if (compare_result == 0) {
+ goto out;
+ }
+
+ compare_result = VLAN_Qos_8021q_compare_by_ref(&(pd_8021q->ingress),
+ &(pref_8021q->ingress));
+ if (compare_result == 0) {
+ goto out;
+ }
+
+ compare_result = VLAN_Qos_8021q_compare_by_ref(&(pd_8021q->egress),
+ &(pref_8021q->egress));
+ if (compare_result == 0) {
+ goto out;
+ }
+
+ p1 = pd_8021q->parent;
+ p2 = pref_8021q->parent;
+ CHARS_COMPARE_BY_REF(p1, p2, compare_result);
+ if (compare_result == 0) {
+ goto out;
+ }
+ }
+
+ out:
+ return compare_result;
+
+}
+
+static int br_prop_filter_by_ref(const BR_Prop *pbr_prop, void *pref)
+{
+ int compare_result = 1;
+ BR_Prop *ref = (BR_Prop *)pref;
+ char *p1, *p2;
+
+ p1 = pbr_prop->bridge_id;
+ p2 = ref->bridge_id;
+ CHARS_COMPARE_BY_REF(p1, p2, compare_result);
+ if (compare_result == 0) {
+ goto out;
+ }
+
+ NUM_COMPARE_BY_REF(pbr_prop->STP, ref->STP,
+ compare_result, NUM_NOT_GOT);
+ if (compare_result == 0) {
+ goto out;
+ }
+
+ NUM_COMPARE_BY_REF(pbr_prop->type, ref->type,
+ compare_result, BR_TYPE_NOT_GOT);
+ if (compare_result == 0) {
+ goto out;
+ }
+
+ NUM_COMPARE_BY_REF(pbr_prop->port_num, ref->port_num,
+ compare_result, NUM_NOT_GOT);
+ /* skip the comparation of ports it attached, user can define
+ a special filter for that */
+ out:
+ return compare_result;
+}
+
+int eth_iface_filter_by_ref(const EthIface *piface, void *pref)
+{
+ int compare_result = 1;
+ EthIface *ref = (EthIface *)pref;
+ char *p1, *p2;
+
+ p1 = piface->name;
+ p2 = ref->name;
+ CHARS_COMPARE_BY_REF(p1, p2, compare_result);
+ if (compare_result == 0) {
+ goto out;
+ }
+
+ p1 = piface->dep_ifname;
+ p2 = ref->dep_ifname;
+ CHARS_COMPARE_BY_REF(p1, p2, compare_result);
+ if (compare_result == 0) {
+ goto out;
+ }
+
+ p1 = piface->attach_bridge;
+ p2 = ref->attach_bridge;
+ CHARS_COMPARE_BY_REF(p1, p2, compare_result);
+ if (compare_result == 0) {
+ goto out;
+ }
+
+ p1 = piface->mac;
+ p2 = ref->mac;
+ CHARS_COMPARE_CASE_BY_REF(p1, p2, compare_result);
+ if (compare_result == 0) {
+ goto out;
+ }
+
+ /* special case for eth_type */
+ NUM_COMPARE_BY_REF((piface->eth_type & ETH_TYPE_BASE_MASK),
+ (ref->eth_type & ETH_TYPE_BASE_MASK),
+ compare_result, ETH_TYPE_NOT_GOT);
+ if (compare_result == 0) {
+ goto out;
+ }
+ NUM_COMPARE_BY_REF((piface->eth_type & ETH_TYPE_SUB_MASK),
+ (ref->eth_type & ETH_TYPE_SUB_MASK),
+ compare_result, ETH_TYPE_NOT_GOT);
+ if (compare_result == 0) {
+ goto out;
+ }
+
+ NUM_COMPARE_BY_REF(piface->run_prop.status, ref->run_prop.status,
+ compare_result, NUM_NOT_GOT);
+ if (compare_result == 0) {
+ goto out;
+ }
+
+ if (ref->pbr_prop != NULL) {
+ if (piface->pbr_prop != NULL) {
+ compare_result = br_prop_filter_by_ref(piface->pbr_prop,
+ ref->pbr_prop);
+ } else {
+ compare_result = 0;
+ }
+ if (compare_result == 0) {
+ goto out;
+ }
+ }
+
+ if (ref->pvlan_prop != NULL) {
+ if (piface->pvlan_prop != NULL) {
+ compare_result = vlan_prop_filter_by_ref(piface->pvlan_prop,
+ ref->pvlan_prop);
+
+ } else {
+ compare_result = 0;
+ }
+ if (compare_result == 0) {
+ goto out;
+ }
+ }
+
+ out:
+ return compare_result;
+}
+
+int eth_iface_filter_by_refname(const EthIface *piface, void *pref)
+{
+ int compare_result = 1;
+ EthIface *ref = (EthIface *)pref;
+ char *p1, *p2;
+
+ p1 = piface->name;
+ p2 = ref->name;
+ CHARS_COMPARE_BY_REF(p1, p2, compare_result);
+ if (compare_result == 0) {
+ goto out;
+ }
+
+ out:
+ return compare_result;
+}
+
+int eth_iface_filter_vlans(const EthIface *piface, void *nouse)
+{
+ if (piface->name == NULL) {
+ return 0;
+ }
+ if (NULL == strstr(piface->name, ".")) {
+ return 0;
+ } else {
+ return 1;
+ }
+}
+
+/* the judgement condition is weak, but I can't find a better way */
+int eth_iface_filter_peths(const EthIface *piface, void *nouse)
+{
+ if (!(piface->eth_type & ETH_TYPE_ETHER_ANY)) {
+ return 0;
+ }
+ if (piface->eth_type & ETH_TYPE_ETHER_SUB_BRIDGE) {
+ return 0;
+ }
+ if (piface->eth_type & ETH_TYPE_ETHER_SUB_VLAN) {
+ return 0;
+ }
+ if (piface->dep_ifname != NULL) {
+ return 0;
+ }
+ if (NULL != strstr(piface->name, ".")) {
+ return 0;
+ }
+ /* this filter NetUSB etc */
+ if (NULL == strstr(piface->name, "eth")) {
+ return 0;
+ }
+
+ return 1;
+}
diff --git a/libnetwork/host_network_basic.h b/libnetwork/host_network_basic.h
new file mode 100644
index 0000000..f782e51
--- /dev/null
+++ b/libnetwork/host_network_basic.h
@@ -0,0 +1,158 @@
+/*
+ * Copyright IBM Corp. 2012
+ *
+ * Authors:
+ * Wenchao Xia <xiawenc(a)cn.ibm.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ */
+
+#ifndef NETWORK_BASIC_HOST_H
+#define NETWORK_BASIC_HOST_H
+
+#include "dll_magic.h"
+
+/* value defines */
+#define MAX_IFACE_NUM 4096
+
+#define NUM_NOT_GOT -1
+
+#define ETH_TYPE_BASE_MASK 0xff00
+#define ETH_TYPE_SUB_MASK 0x00ff
+typedef enum {
+ ETH_TYPE_NOT_GOT = 0x0000,
+ ETH_TYPE_UNKNOWN = 0x0100,
+ ETH_TYPE_OTHER = 0x0200,
+ ETH_TYPE_ETHER_ANY = 0x0400,
+ ETH_TYPE_ETHER_SUB_PHYSICAL = 0x0001,
+ ETH_TYPE_ETHER_SUB_BRIDGE = 0x0002,
+ ETH_TYPE_ETHER_SUB_VLAN = 0x0004
+} EthType;
+
+typedef enum {
+ BR_TYPE_NOT_GOT = NUM_NOT_GOT,
+ BR_TYPE_UNKNOWN = 0,
+ BR_TYPE_SWITCH = 1,
+ BR_TYPE_NAT = 2
+} BrType;
+
+typedef enum {
+ VLAN_TYPE_NOT_GOT = NUM_NOT_GOT,
+ VLAN_TYPE_802_1_Q = 1,
+ VLAN_TYPE_802_1_QBG = 2,
+ VLAN_TYPE_802_1_QBH = 4
+} VLANType;
+
+typedef struct BR_Prop {
+ char *bridge_id;
+ int STP;
+ BrType type;
+ char **port_names;
+ int port_num;
+} BR_Prop;
+
+/* status use RFC 2863 operational status */
+typedef struct Run_Prop {
+ long long rx_bytes;
+ long long tx_bytes;
+ int status;
+} Run_Prop;
+
+typedef struct VLAN_Qos_8021q_elem {
+ int from;
+ int to;
+} VLAN_Qos_8021q_elem;
+
+typedef struct VLAN_Qos_8021q {
+ VLAN_Qos_8021q_elem values[8];
+ int count;
+} VLAN_Qos_8021q;
+
+typedef struct VLAN_Prop_8021q {
+ int vlan_id;
+ int reorder_hdr;
+ int priv_flag;
+ VLAN_Qos_8021q ingress;
+ VLAN_Qos_8021q egress;
+ char *parent;
+} VLAN_Prop_8021q;
+
+/* HP vlan standard, TBD */
+typedef struct VLAN_Prop_8021qbg {
+ int invalid;
+} VLAN_Prop_8021qbg;
+
+/* Cisco and VMware vlan standard, TBD */
+typedef struct VLAN_Prop_8021qbh {
+ int invalid;
+} VLAN_Prop_8021qbh;
+
+typedef struct VLAN_Prop {
+ int vlan_type;
+ union {
+ VLAN_Prop_8021q prop_8021q;
+ VLAN_Prop_8021qbg prop_8021qbg;
+ VLAN_Prop_8021qbh prop_8021qbh;
+ } props;
+} VLAN_Prop;
+
+/* EthIface is logical devices include eth ports and bridges */
+typedef struct EthIface {
+ char *name;
+ char *dep_ifname; /* parent dev name */
+ char *attach_bridge; /* bridge the iface is attached to */
+ char *mac;
+ EthType eth_type;
+ Run_Prop run_prop;
+ /* optional properties */
+ BR_Prop *pbr_prop;
+ VLAN_Prop *pvlan_prop;
+} EthIface;
+
+typedef struct EthIfacesList {
+ EthIface *pifaces[MAX_IFACE_NUM];
+ int count;
+} EthIfacesList;
+
+typedef int (*eth_iface_filter_func)(const EthIface *piface, void *opaque);
+
+/* uninit functions are only called when there is resource malloc */
+DLL_PUBLIC void vlan_prop_init(VLAN_Prop *pvlan_prop, int vlan_type);
+DLL_PUBLIC void vlan_prop_uninit(VLAN_Prop *pvlan_prop);
+
+DLL_PUBLIC void br_prop_init(BR_Prop *pbr_prop);
+DLL_PUBLIC void br_prop_uninit(BR_Prop *pbr_prop);
+
+DLL_PUBLIC void eth_iface_print(EthIface *piface);
+DLL_PUBLIC void eth_iface_init(EthIface *piface);
+DLL_PUBLIC void eth_iface_add_br_prop(EthIface *piface);
+DLL_PUBLIC void eth_iface_add_vlan_prop(EthIface *piface, int vlan_type);
+DLL_PUBLIC void eth_iface_uninit(EthIface *piface);
+DLL_PUBLIC void eth_ifaces_clear(EthIface **ppifaces, int num);
+
+DLL_PUBLIC void eth_ifaceslist_init(EthIfacesList *plist);
+DLL_PUBLIC void eth_ifaceslist_uninit(EthIfacesList *plist);
+DLL_PUBLIC void eth_ifaceslist_print(EthIfacesList *plist);
+DLL_PUBLIC int eth_ifaceslist_add(EthIfacesList *plist, EthIface *piface);
+
+/* this function assume dest have been uninited if it was used before*/
+DLL_PUBLIC void eth_iface_dup(EthIface *dest, const EthIface *src);
+
+/* see if it is refered to the same device */
+DLL_PUBLIC int eth_iface_compare(const EthIface *p1, const EthIface *p2);
+
+/* merge the properties that dest do not have value set, if style is set to 1,
+ the char* properties was moved instead of copy, safely reduce the memory
+ fragments, but src is modified. */
+DLL_PUBLIC void eth_iface_merge(EthIface *dest, EthIface *src, int style);
+
+DLL_PUBLIC int eth_iface_filter_by_ref(const EthIface *piface, void *pref);
+DLL_PUBLIC int eth_iface_filter_by_refname(const EthIface *piface, void *pref);
+DLL_PUBLIC int eth_iface_filter_vlans(const EthIface *piface, void *nouse);
+DLL_PUBLIC int eth_iface_filter_peths(const EthIface *piface, void *nouse);
+
+
+#endif
--
1.7.1
12 years, 7 months
[V4 PATCH 4/8] vlan library - add host network implemention
by Wenchao Xia
This patch use libnl-1.1 and ioctl bridge functions in patch 3.
Signed-off-by: Wenchao Xia <xiawenc(a)cn.ibm.com>
---
libnetwork/host_network_implement_OSAPI.c | 366 +++++++++++++++++++++++++++++
libnetwork/host_network_implement_OSAPI.h | 21 ++
2 files changed, 387 insertions(+), 0 deletions(-)
create mode 100644 libnetwork/host_network_implement_OSAPI.c
create mode 100644 libnetwork/host_network_implement_OSAPI.h
diff --git a/libnetwork/host_network_implement_OSAPI.c b/libnetwork/host_network_implement_OSAPI.c
new file mode 100644
index 0000000..2efcf37
--- /dev/null
+++ b/libnetwork/host_network_implement_OSAPI.c
@@ -0,0 +1,366 @@
+/*
+ * Copyright IBM Corp. 2012
+ *
+ * Authors:
+ * Wenchao Xia <xiawenc(a)cn.ibm.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ */
+
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <net/if_arp.h>
+#include <linux/if_vlan.h>
+
+#include <netlink/netlink.h>
+#include <netlink/socket.h>
+#include <netlink/list.h>
+#include <netlink/object.h>
+#include <netlink/object-api.h>
+#include <netlink/route/link.h>
+#include <netlink/route/link/vlan.h>
+#include <netlink/route/link/info-api.h>
+
+#include "host_network_implement_bridge.h"
+#include "host_network_implement_OSAPI.h"
+#include "host_network_helper.h"
+#include "host_network_error.h"
+
+/* macro defines */
+#define LN_PRINT_LEVEL 4
+
+struct nl_add2list_param {
+ EthIfacesList *plist;
+ struct nl_cache *cache;
+} ;
+
+/* libnl1 lackes a way to see if it is vlan8021q, added an implemention here*/
+static int rtnl_link_is_vlan(struct rtnl_link *link)
+{
+ char* type = rtnl_link_get_info_type(link);
+ if (type == NULL) {
+ return 0;
+ }
+ return !strcmp(type, "vlan");
+}
+
+/* the bridge seems have 0 value when it is up , so adjust the value,
+ and found out which are physical cards */
+static int host_iface_adjust(EthIface *piface)
+{
+ if (1 == eth_iface_filter_peths(piface, NULL)) {
+ piface->eth_type |= (ETH_TYPE_ETHER_ANY | ETH_TYPE_ETHER_SUB_PHYSICAL);
+ }
+ return 1;
+}
+
+static void find_iface_attached_bridge(EthIfacesList *peth_list, EthIface *pbr)
+{
+ int i, j;
+ char *name_on_br, *name_iface;
+ if (pbr->pbr_prop == NULL) {
+ return;
+ }
+ i = 0;
+ while (i < pbr->pbr_prop->port_num) {
+ name_on_br = pbr->pbr_prop->port_names[i];
+ j = 0;
+ while (j < peth_list->count) {
+ name_iface = peth_list->pifaces[j]->name;
+ if (0 == strcmp(name_on_br, name_iface)) {
+ if (peth_list->pifaces[j]->attach_bridge == NULL) {
+ peth_list->pifaces[j]->attach_bridge =
+ SAFE_STRDUP(pbr->name);
+ }
+ break;
+ }
+ j++;
+ }
+ i++;
+ }
+}
+
+/* assuming that one peth would be attached to at most 1 bridge */
+static void merge_eth_list_for_bridge(EthIfacesList *peth_list,
+ EthIfacesList *pbr_list,
+ int flag)
+{
+ int i, j;
+ i = 0;
+ while (i < pbr_list->count) {
+ find_iface_attached_bridge(peth_list, pbr_list->pifaces[i]);
+ j = 0;
+ while (j < peth_list->count) {
+ if (1 == eth_iface_compare(peth_list->pifaces[j],
+ pbr_list->pifaces[i])) {
+ /* found the matched device, merge them */
+ eth_iface_merge(peth_list->pifaces[j],
+ pbr_list->pifaces[i], flag);
+ break;
+ }
+ j++;
+ }
+ i++;
+ }
+ return;
+}
+
+static void ln_link_print(struct rtnl_link *link)
+{
+ char *name, *qdisk, *type = NULL;
+ const char *ifalias = NULL;
+ int ifindex, flags, mtu, txqlen, family, arptype, getlink, master, operstate, linkmode;
+ uint32_t num_vf = 0;
+ int ret, i;
+ int vlanid, vlanflag, egress_num = 0;
+ uint32_t *ingress_map;
+ struct vlan_map *egress_map;
+
+ qdisk = rtnl_link_get_qdisc(link);
+ name = rtnl_link_get_name(link);
+ flags = rtnl_link_get_flags(link);
+ mtu = rtnl_link_get_mtu(link);
+ txqlen = rtnl_link_get_txqlen(link);
+ ifindex = rtnl_link_get_ifindex(link);
+ family = rtnl_link_get_family(link);
+ arptype = rtnl_link_get_arptype(link);
+ getlink = rtnl_link_get_link(link);
+ master = rtnl_link_get_master(link);
+ operstate = rtnl_link_get_operstate(link);
+ linkmode = rtnl_link_get_linkmode(link);
+
+ CMD_DEBUG(1, "link name %s, alias %s, qdisk %s, type %s,\n"
+ "--ifindex 0x%x, flags 0x%x, mtu 0x%x, txqlen 0x%x, family 0x%x, arptype 0x%x,\n"
+ "--getlink 0x%x, master 0x%x, operstate 0x%x, linkmode 0x%x, vf_ret %d with num_vf 0x%x.\n",
+ name, ifalias, qdisk, type,
+ ifindex, flags, mtu, txqlen, family, arptype,
+ getlink, master, operstate, linkmode, ret, num_vf);
+
+ if (rtnl_link_is_vlan(link)) {
+ vlanid = rtnl_link_vlan_get_id(link);
+ vlanflag = rtnl_link_vlan_get_flags(link);
+ ingress_map = rtnl_link_vlan_get_ingress_map(link);
+ egress_map = rtnl_link_vlan_get_egress_map(link, &egress_num);
+ CMD_DEBUG(1, "--vlan properties:\n"
+ "----id %d, vlanflag 0x%x.",
+ vlanid, vlanflag);
+ CMD_DEBUG(1, "\n----ingress: ");
+ if (ingress_map != NULL) {
+ for (i = 0; i <= VLAN_PRIO_MAX; i++) {
+ CMD_DEBUG(1, "0x%x, ", ingress_map[i]);
+ }
+ }
+ CMD_DEBUG(1, "\n----egress: ");
+ if (egress_map != NULL) {
+ i = 0;
+ while (i < egress_num) {
+ CMD_DEBUG(1, "[%d %d], ", egress_map[i].vm_from, egress_map[i].vm_to);
+ i++;
+ }
+ }
+ CMD_DEBUG(1, "\n");
+ }
+}
+
+static void nl_add2list_func(struct nl_object *obj, void *opaque)
+{
+ struct rtnl_link *link;
+ struct nl_cache *cache;
+ struct rtnl_link *ll;
+ struct nl_addr *addr;
+ uint32_t *ingress_map;
+ int egress_num = 0, opstate;
+ struct vlan_map *egress_map;
+ EthIfacesList *plist;
+ EthIface tface;
+ VLAN_Prop_8021q *pprop_8021q;
+ char buf[128];
+ int t, i;
+
+ struct nl_add2list_param *pparam = (struct nl_add2list_param *)opaque;
+ plist = pparam->plist;
+ cache = pparam->cache;
+ link = (struct rtnl_link *)obj;
+
+ if (CMD_DEBUG_LEVEL && (LN_PRINT_LEVEL) <= CMD_DEBUG_LEVEL) {
+ ln_link_print(link);
+ }
+
+ /* get properties */
+ eth_iface_init(&tface);
+
+ /* get name */
+ tface.name = SAFE_STRDUP(rtnl_link_get_name(link));
+
+ /* get parent */
+ t = rtnl_link_get_link(link);
+ if (t > 0) {
+ ll = rtnl_link_get(cache, t);
+ if (ll == NULL) {
+ CU_DEBUG("failed to find interface with index %d.", t);
+ goto out;
+ }
+ tface.dep_ifname = SAFE_STRDUP(rtnl_link_get_name(ll));
+ rtnl_link_put(ll);
+ }
+
+ /* get mac */
+ addr =rtnl_link_get_addr(link);
+ if (addr && !nl_addr_iszero(addr)) {
+ nl_addr2str(addr, buf, sizeof(buf));
+ tface.mac = SAFE_STRDUP(buf);
+ }
+
+ /* get main type */
+ t = rtnl_link_get_arptype(link);
+ if (t == ARPHRD_ETHER) {
+ tface.eth_type = ETH_TYPE_ETHER_ANY;
+ } else {
+ tface.eth_type = ETH_TYPE_OTHER;
+ }
+
+ tface.run_prop.status = rtnl_link_get_operstate(link);
+
+ /* get vlan */
+ if (rtnl_link_is_vlan(link)) {
+ SAFE_MALLOC(tface.pvlan_prop, sizeof(VLAN_Prop));
+ vlan_prop_init(tface.pvlan_prop, VLAN_TYPE_802_1_Q);
+ pprop_8021q = &(tface.pvlan_prop->props.prop_8021q);
+ tface.eth_type |= ETH_TYPE_ETHER_SUB_VLAN;
+ pprop_8021q->vlan_id = rtnl_link_vlan_get_id(link);
+ pprop_8021q->reorder_hdr = (rtnl_link_vlan_get_flags(link) &
+ VLAN_FLAG_REORDER_HDR);
+ /* at any time parent of vlan8021.q is just what it depends on */
+ pprop_8021q->parent = SAFE_STRDUP(tface.dep_ifname);
+ ingress_map = rtnl_link_vlan_get_ingress_map(link);
+ egress_map = rtnl_link_vlan_get_egress_map(link, &egress_num);
+ if (ingress_map != NULL) {
+ for (i = 0; i <= VLAN_PRIO_MAX; i++) {
+ pprop_8021q->ingress.values[i].from = i;
+ pprop_8021q->ingress.values[i].to = ingress_map[i];
+ }
+ pprop_8021q->ingress.count = VLAN_PRIO_MAX;
+ i = 0;
+ while (i < egress_num) {
+ pprop_8021q->egress.values[i].from = egress_map[i].vm_from;
+ pprop_8021q->egress.values[i].to = egress_map[i].vm_to;
+ i++;
+ }
+ pprop_8021q->egress.count = egress_num;
+ }
+ }
+
+ /* put result to list */
+ if (1 != eth_ifaceslist_add(plist, &tface)) {
+ CU_DEBUG("failed to add device to list.");
+ goto out;
+ }
+
+ out:
+ eth_iface_uninit(&tface);
+}
+
+static int get_host_eth_ifaces_osapi_netlink(EthIfacesList *plist)
+{
+ struct nl_handle *nlh = NULL;
+ struct nl_cache *cache = NULL;
+ int ret, rtnl_ret;
+ struct nl_add2list_param param;
+
+ nlh = nl_handle_alloc();
+ if (nlh == NULL) {
+ CU_DEBUG("unable to allocate nl handle.");
+ ret = ERR_LIBNETLINK;
+ }
+ rtnl_ret = nl_connect(nlh, NETLINK_ROUTE);
+ if (rtnl_ret < 0) {
+ CU_DEBUG("error in connect to kernel, return %d, err %s.\n",
+ rtnl_ret, nl_geterror());
+ ret = ERR_LIBNETLINK;
+ }
+
+ cache = rtnl_link_alloc_cache(nlh);
+ if (cache == NULL) {
+ CU_DEBUG("error in talking to kernel.\n");
+ ret = ERR_LIBNETLINK;
+ }
+
+ param.plist = plist;
+ param.cache = cache;
+ nl_cache_foreach(cache, nl_add2list_func, ¶m);
+ if (plist->count >= MAX_IFACE_NUM) {
+ CU_DEBUG("too much device found.");
+ ret = ERR_DEVICE_EXCEED_MAXNUM;
+ goto out;
+ }
+
+ ret = 1;
+
+ out:
+ nl_cache_free(cache);
+ nl_close(nlh);
+ nl_handle_destroy(nlh);
+
+ return ret;
+}
+
+int get_host_eth_ifaces_osapi(EthIfacesList *plist,
+ eth_iface_filter_func filter_func, void *filter_opaque)
+{
+ int retvalue;
+ EthIfacesList *ifaces1, *ifaces2;
+ int i;
+ int filter_ret;
+ int count = 0;
+ SAFE_MALLOC(ifaces1, sizeof(EthIfacesList));
+ SAFE_MALLOC(ifaces2, sizeof(EthIfacesList));
+ eth_ifaceslist_init(ifaces1);
+ eth_ifaceslist_init(ifaces2);
+
+ retvalue = get_host_eth_ifaces_osapi_netlink(ifaces1);
+ if (retvalue != 1) {
+ goto out;
+ }
+
+ retvalue = get_host_eth_ifaces_osapi_bridge(ifaces2);
+ if (retvalue != 1) {
+ goto out;
+ }
+ /* merge the information */
+ merge_eth_list_for_bridge(ifaces1, ifaces2, 1);
+ eth_ifaceslist_uninit(ifaces2);
+
+ /* filter the result */
+ i = 0;
+ while (i < ifaces1->count) {
+ /* see if the result need to be put to the list */
+ filter_ret = 1;
+ if (filter_func != NULL) {
+ filter_ret = filter_func(ifaces1->pifaces[i], filter_opaque);
+ }
+ if (filter_ret == 1) {
+ if (count >= MAX_IFACE_NUM) {
+ retvalue = ERR_DEVICE_EXCEED_MAXNUM;
+ goto out;
+ }
+ host_iface_adjust(ifaces1->pifaces[i]);
+ plist->pifaces[count] = ifaces1->pifaces[i];
+ ifaces1->pifaces[i] = NULL;
+ count++;
+ }
+ i++;
+ }
+
+ out:
+ eth_ifaceslist_uninit(ifaces1);
+ SAFE_FREE(ifaces1);
+ eth_ifaceslist_uninit(ifaces2);
+ SAFE_FREE(ifaces2);
+ plist->count = count;
+ return retvalue;
+}
diff --git a/libnetwork/host_network_implement_OSAPI.h b/libnetwork/host_network_implement_OSAPI.h
new file mode 100644
index 0000000..34a261b
--- /dev/null
+++ b/libnetwork/host_network_implement_OSAPI.h
@@ -0,0 +1,21 @@
+/*
+ * Copyright IBM Corp. 2012
+ *
+ * Authors:
+ * Wenchao Xia <xiawenc(a)cn.ibm.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ */
+
+#ifndef HOST_NETWORK_IMPLEMENT_OSAPI_H
+#define HOST_NETWORK_IMPLEMENT_OSAPI_H
+
+#include "host_network_basic.h"
+
+int get_host_eth_ifaces_osapi(EthIfacesList *plist,
+ eth_iface_filter_func filter_func, void *filter_opaque);
+
+#endif
--
1.7.1
12 years, 7 months
[V4 PATCH 1/8] vlan library - Makefile system change
by Wenchao Xia
building system is changed to check libnl-devel-1.1. Also added Makefile in
sub dir. In sub dir CFLAGS and LDFLAGS were overwritten, because they have
other values set when configure was excuted. Libnetwork have -fPIC and
-fvisibility=hidden -D DLL_BUILD flags set.
Signed-off-by: Wenchao Xia <xiawenc(a)cn.ibm.com>
---
Makefile.am | 2 +-
acinclude.m4 | 9 +++++++++
configure.ac | 8 ++++++++
libnetwork/Makefile.am | 37 +++++++++++++++++++++++++++++++++++++
libvirt-cim.spec.in | 2 ++
5 files changed, 57 insertions(+), 1 deletions(-)
create mode 100644 libnetwork/Makefile.am
diff --git a/Makefile.am b/Makefile.am
index 94dc5f3..6689550 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,7 +1,7 @@
# Copyright IBM Corp. 2007
AUTOMAKE_OPTIONS=dist-bzip2
-SUBDIRS = libxkutil src doc base_schema
+SUBDIRS = libnetwork libxkutil src doc base_schema
MOFS = \
$(top_srcdir)/schema/ComputerSystem.mof \
diff --git a/acinclude.m4 b/acinclude.m4
index e0f76b6..3a2f76f 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -387,3 +387,12 @@ AC_DEFUN([SET_CSET],
CFLAGS="$CFLAGS $cs $rv"
]
)
+
+AC_DEFUN([CHECK_LIBNL],
+ [
+ PKG_CHECK_MODULES([LIBNL], [libnl-1 >= 1.1])
+ AC_SUBST([LIBNL_CFLAGS])
+ AC_SUBST([LIBNL_LIBS])
+# CPPFLAGS="$CPPFLAGS $LIBNL_CFLAGS"
+# LDFLAGS="$LDFLAGS $LIBNL_LIBS"
+ ])
diff --git a/configure.ac b/configure.ac
index 0f85baa..78a7438 100644
--- a/configure.ac
+++ b/configure.ac
@@ -50,6 +50,12 @@ CC_WARNINGS="\
CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -D_LARGEFILE64_SOURCE"
+# following are for libnetwork
+LIBNETWORK_CFLAGS="-fvisibility=hidden"
+LIBNETWORK_DEFINES="-D DLL_BUILD"
+AC_SUBST(LIBNETWORK_CFLAGS)
+AC_SUBST(LIBNETWORK_DEFINES)
+
# Configure command line options
AC_ARG_VAR([CIMSERVER],[the target CIM server (pegasus|sfcb|openwbem|sniacimom).
])
@@ -141,6 +147,7 @@ AC_CONFIG_FILES([
base_schema/install_base_schema.sh
base_schema/Makefile
libxkutil/Makefile
+ libnetwork/Makefile
src/Makefile
doc/Makefile
Makefile
@@ -165,6 +172,7 @@ CHECK_LIBXML2
CHECK_LIBCU
CHECK_LIBUUID
CHECK_LIBCONFIG
+CHECK_LIBNL
CFLAGS_STRICT="-Werror"
diff --git a/libnetwork/Makefile.am b/libnetwork/Makefile.am
new file mode 100644
index 0000000..aaa33c0
--- /dev/null
+++ b/libnetwork/Makefile.am
@@ -0,0 +1,37 @@
+# Copyright IBM Corp. 2012
+# Auther:
+# Wenchao Xia, <xiawenc(a)cn.ibm.com>
+#
+# Try build a dynamic library libnetwork.so, which
+# include libnl-3 and libbridge binaries. Doing this is
+# because there is no devel-libbridge.rpm, and there are
+# many program still using libnl1.so, which conflicts with
+# libnl-3.
+# Exported symbols are strictly limited by Macro DLL_PUBLIC
+# to reduce name space polution.
+# It need libcmpiutil to use CU_DEBUG facility.
+# A test program is generated named as libnetwork_test.
+
+LDFLAGS = $(LIBNETWORK_DEFINES)
+
+CFLAGS = $(CFLAGS_STRICT) \
+ -DLIBVIRTCIM_CONF=\"@sysconfdir@/@PACKAGE@.conf\" \
+ $(LIBNETWORK_CFLAGS) $(LIBNETWORK_DEFINES) \
+ -I $(top_srcdir)/libnetwork/include
+
+
+noinst_HEADERS = host_network_API.h host_network_basic.h host_network_helper.h host_network_error.h \
+ host_network_implement_OSAPI.h host_network_implement_bridge.h dll_magic.h
+noinst_HEADERS += include/netlink/route/link/vlan.h include/netlink/route/link/info-api.h
+
+lib_LTLIBRARIES = libnetwork.la
+
+libnetwork_la_SOURCES = host_network_API.c host_network_basic.c host_network_helper.c \
+ host_network_implement_OSAPI.c host_network_implement_bridge.c
+libnetwork_la_LDFLAGS = -version-info @VERSION_INFO@ -lcmpiutil $(LIBNL_LIBS)
+
+noinst_PROGRAMS = libnetwork_test
+
+libnetwork_test_SOURCES = libnetwork_test.c
+libnetwork_test_LDFLAGS = -lcmpiutil
+libnetwork_test_LDADD = libnetwork.la
diff --git a/libvirt-cim.spec.in b/libvirt-cim.spec.in
index d78eee7..5fac166 100644
--- a/libvirt-cim.spec.in
+++ b/libvirt-cim.spec.in
@@ -13,9 +13,11 @@ Requires: libxml2 >= 2.6.0
Requires: libvirt >= 0.9.0
Requires: unzip
Requires: tog-pegasus
+Requires: libnl >= 1.1
BuildRequires: libcmpiutil >= 0.5.4
BuildRequires: tog-pegasus-devel
BuildRequires: libvirt-devel >= 0.9.0
+BuildRequires: libnl-devel >= 1.1
# In RHEL5 uuid-devel is provided by e2fsprogs
%if 0%{?el5}
--
1.7.1
12 years, 7 months
[V4 PATCH 0/8] vlan extension - add readonly library code
by Wenchao Xia
These patches just add new library in libvirt-cim and do not touch
existing providers. It have a testing program added to see the functionalities.
V2: fix some problem in filter out NICs.
V3: using libnl3 and libbridge instead of string parsing, applys to libvirt-cim
0.5.5.
V4: switched to libnl1, using custom codes for bridge. Small fix about date
declaration. libnl1 provides less functions such as single root NICs, but it is
workable for vlan 8021q. Patch applys to latest libvirt-cim from git.
repository:
git://gitorious.org/libvirt-cim_develop/libvirt-cim_develop.git
page:
https://gitorious.org/libvirt-cim_develop/libvirt-cim_develop
Wenchao Xia (8):
vlan library - Makefile system change
vlan library - add missing header files in libnl-devel 1.1
vlan library - add a simple implemention for bridge
vlan library - add host network implemention
vlan library - add basic structure and related functions
vlan library - add help functions and error defines
vlan library - add interface for CIM model code
vlan library - testing program for libnetwork
Makefile.am | 2 +-
acinclude.m4 | 9 +
configure.ac | 8 +
libnetwork/Makefile.am | 37 ++
libnetwork/dll_magic.h | 13 +
libnetwork/host_network_API.c | 30 +
libnetwork/host_network_API.h | 25 +
libnetwork/host_network_basic.c | 656 ++++++++++++++++++++++
libnetwork/host_network_basic.h | 158 ++++++
libnetwork/host_network_error.h | 23 +
libnetwork/host_network_helper.c | 266 +++++++++
libnetwork/host_network_helper.h | 177 ++++++
libnetwork/host_network_implement_OSAPI.c | 366 ++++++++++++
libnetwork/host_network_implement_OSAPI.h | 21 +
libnetwork/host_network_implement_bridge.c | 224 ++++++++
libnetwork/host_network_implement_bridge.h | 8 +
libnetwork/include/netlink/route/link/info-api.h | 71 +++
libnetwork/include/netlink/route/link/vlan.h | 55 ++
libnetwork/libnetwork_test.c | 91 +++
libvirt-cim.spec.in | 2 +
20 files changed, 2241 insertions(+), 1 deletions(-)
create mode 100644 libnetwork/Makefile.am
create mode 100644 libnetwork/dll_magic.h
create mode 100644 libnetwork/host_network_API.c
create mode 100644 libnetwork/host_network_API.h
create mode 100644 libnetwork/host_network_basic.c
create mode 100644 libnetwork/host_network_basic.h
create mode 100644 libnetwork/host_network_error.h
create mode 100644 libnetwork/host_network_helper.c
create mode 100644 libnetwork/host_network_helper.h
create mode 100644 libnetwork/host_network_implement_OSAPI.c
create mode 100644 libnetwork/host_network_implement_OSAPI.h
create mode 100644 libnetwork/host_network_implement_bridge.c
create mode 100644 libnetwork/host_network_implement_bridge.h
create mode 100644 libnetwork/include/netlink/route/link/info-api.h
create mode 100644 libnetwork/include/netlink/route/link/vlan.h
create mode 100644 libnetwork/libnetwork_test.c
12 years, 7 months
[PATCH v2 0/2] Implementation of a linked list helper
by Eduardo Lima (Etrunko)
From: "Eduardo Lima (Etrunko)" <eblima(a)br.ibm.com>
This series provides a generic linked list implementation for libxkutil that is
based on the one originally developed for the libvirt domain events support
recently integrated upstream.
As test case I ported the ComputerSystemIndication provider code to use this
list implementation. In the near future it will be also used by the event loop
that I am currently working on to allow systems with libvirt older than 0.9.0
to make use of the same feature.
Other possible use cases would be to port the code of libxkutil/*_parsing* to
also use the list implementation instead of static arrays.
Changes from v1:
- Fix version iformation in Makefile.am
--
Eduardo de Barros Lima
Software Engineer, Open Virtualization
Linux Technology Center - IBM/Brazil
eblima(a)br.ibm.com
Eduardo Lima (Etrunko) (2):
libxkutil: Linked list helper
CSI: Use list helper implementation
libxkutil/Makefile.am | 51 ++++++--
libxkutil/list_util.c | 231 +++++++++++++++++++++++++++++++++++
libxkutil/list_util.h | 76 ++++++++++++
src/Virt_ComputerSystemIndication.c | 95 ++++-----------
4 files changed, 370 insertions(+), 83 deletions(-)
create mode 100644 libxkutil/list_util.c
create mode 100644 libxkutil/list_util.h
--
1.7.7.5
12 years, 7 months