[PATCH] Host agent connection test
by Adam Stokes
---
src/CMakeLists.txt | 2 ++
src/tests/host-agent.t.in | 21 +++++++++++++++++++++
2 files changed, 23 insertions(+), 0 deletions(-)
create mode 100644 src/tests/host-agent.t.in
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index b95bbc6..e2dbd5d 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -186,4 +186,6 @@ install(TARGETS mcommon mhost msrv DESTINATION lib${LIB_SUFFIX})
install(FILES ${SCHEMAS} DESTINATION share/matahari)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/matahari.h DESTINATION include)
+# tests
+configure_file (${CMAKE_CURRENT_SOURCE_DIR}/tests/host-agent.t.in ${CMAKE_CURRENT_BINARY_DIR}/tests/host-agent.t)
diff --git a/src/tests/host-agent.t.in b/src/tests/host-agent.t.in
new file mode 100644
index 0000000..f671c04
--- /dev/null
+++ b/src/tests/host-agent.t.in
@@ -0,0 +1,21 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use Test::Simple tests => 1; # Increment as tests are added
+
+=head1
+Matahari host agent test suite
+=cut
+
+my $binary = "matahari-hostd";
+my $broker_host = @MATAHARI_BROKER@;
+my $broker_port = @MATAHARI_PORT@;
+
+my $cmd = "$binary -b $broker_host -p $broker_port";
+`$cmd`;
+
+my @args = ("pidof", $binary);
+ok( $? eq 0, "$binary is running");
+
+`pkill $binary`;
--
1.7.3.3
13 years
Strategies for virtio-serial connectivity for Qpid
by Ted Ross
There has been some discussion about what the strategy for
Qpid-over-virtio-serial should be. One of the newer considerations is
that the local broker (on the guest) should be optional and is
considered an optimization (for connection concentration). Not using a
local broker makes for a significantly simpler system configuration.
This leaves two possible approaches:
1) Build a virtio-serial plug-in for Qpid
2) Build a tcp-socket proxy that multiplexes tcp connections over
virtio-serial
The advantage of (1) is that it is a better architectural solution and
does not require that we create a new package and a new item that needs
to be configured on guests.
The advantage of (2) is that it might be easier to write in a short time.
Here are some notes on each approach:
1) virtio-serial plug-in
Qpid already has two value-added transport plug-ins, one for RDMA and
one for SSL. Both of these are packaged as a set of shared-object
libraries (a common, a client-side, and a server-side). Either of these
transports can serve as a template for a virtio-serial transport.
The source for these can be found in the Qpid SVN (there's a git also):
http://svn.apache.org/repos/asf/qpid/trunk/qpid
SSL:
qpid/cpp/src/qpid/client/SslConnector.cpp
qpid/cpp/src/qpid/sys/SslPlugin.cpp
qpid/cpp/src/qpid/sys/ssl/*
RDMA:
qpid/cpp/src/qpid/client/RdmaConnector.cpp
qpid/cpp/src/qpid/sys/RdmaIOPlugin.cpp
qpid/cpp/src/qpid/sys/rdma/*
2) tcp-socket proxy
This new function would need to be built as two components, one for
guest/client-side and one for host/server-side.
The client-side would open a listening socket on
localhost:<some-known-port>. When a connection is established to this
port, the resulting IO socket would then be tied to virtio-serial in
such a way that bidirectional data segments can be multiplexed over the
link to the server-side.
The server-side would learn of new connections by means of data arriving
on virtio-serial and make an outbound tcp connection to
localhost:<broker-port> and begin multiplexing and demultiplexing data
segments.
If (1) can be done in a time for the RHEL6.1 deliverable, it would be
the better architectural approach.
13 years, 2 months
Re: [Matahari] RHEL6.1.z: virtio-serial needed in all guest configuration for Virt entitilement
by Perry Myers
(for reference we're talking about making changes to libvirt default
configurations to always include virtio-serial channels so that Matahari
can use it w/o asking end users to add these themselves)
<snip>
> There are two aspects. There is the device XML
>
> <controller type='virtio-serial' index='1'>
> <address type='pci' domain='0x0000' bus='0x00' slot='0x0a' function='0x0'/>
> </controller>
>
> And then n * channels
>
> <channel type='pty'>
> <target type='virtio' name='org.linux-kvm.port.foo'/>
> <address type='virtio-serial' controller='1' bus='0' port='3'/>
> </channel>
>
>
> Normally applications would never add a <controller> themselves,
> because it is done automatically when you add a <channel> device.
> So making virtinst manually add a <controller> is not normal
> practice.
Ok. So what we'd want here is to by default add a virtio-serial channel
in virtinst and vdsm with a name like 'org.matahari-project.port' (or if
we want to be more generic to this just being a qpid transport it could
be org.apache.qpid.port)
And adding that channel would make the creation of the virtio controller
implicit.
>> If the former, then we should add a virtio channel by default on the
>> virtio-serial PCI device that we're adding. If we need to give a name
>> to this, we could just call the channel mgmt or matahari or smth if it
>> needs to be named.
>
> We can't add a channel without knowing exactly how the application
> that will use it, needs it to be configured which isn't something
> we can reliably guess ahead of it being written.
What sort of configuration things need to be decided? Looking at the
channel snippet above it doesn't look unreasonable to decide what it
should look like and then implement the AMQP/virtio-serial transport to
use a preset configuration (assuming the important config info to decide
on is the channel name)
Perry
13 years, 2 months
[PATCH] Sigar win32 network change
by Adam Stokes
- Uses network interface description in place of sigar's
ethX naming scheme. This does not allow for an administrator
to disable/enable the device, but at least gives identifiable
names.
---
include/sigar.h | 8 ++++----
src/os/win32/win32_sigar.c | 13 ++++++-------
2 files changed, 10 insertions(+), 11 deletions(-)
diff --git a/include/sigar.h b/include/sigar.h
index 48974ed..309cd0f 100644
--- a/include/sigar.h
+++ b/include/sigar.h
@@ -529,7 +529,7 @@ typedef struct {
typedef struct {
char default_gateway[SIGAR_INET6_ADDRSTRLEN];
- char default_gateway_interface[16];
+ char default_gateway_interface[256];
char host_name[SIGAR_MAXHOSTNAMELEN];
char domain_name[SIGAR_MAXDOMAINNAMELEN];
char primary_dns[SIGAR_INET6_ADDRSTRLEN];
@@ -556,7 +556,7 @@ typedef struct {
mtu,
window,
irtt;
- char ifname[16];
+ char ifname[256];
} sigar_net_route_t;
typedef struct {
@@ -602,7 +602,7 @@ SIGAR_DECLARE(int) sigar_net_route_list_destroy(sigar_t *sigar,
#define SIGAR_IPV6_ADDR_COMPATv4 0x0080
typedef struct {
- char name[16];
+ char name[256];
char type[64];
char description[256];
sigar_net_address_t hwaddr;
@@ -847,7 +847,7 @@ sigar_net_listen_address_get(sigar_t *sigar,
sigar_net_address_t *address);
typedef struct {
- char ifname[16];
+ char ifname[256];
char type[64];
sigar_net_address_t hwaddr;
sigar_net_address_t address;
diff --git a/src/os/win32/win32_sigar.c b/src/os/win32/win32_sigar.c
index 87076c8..0960ac1 100755
--- a/src/os/win32/win32_sigar.c
+++ b/src/os/win32/win32_sigar.c
@@ -2701,8 +2701,8 @@ sigar_net_interface_list_get(sigar_t *sigar,
}
for (i=0; i<ift->dwNumEntries; i++) {
- char name[16];
- int key;
+ char name[256];
+ int key, j;
MIB_IFROW *ifr = ift->table + i;
sigar_cache_entry_t *entry;
@@ -2710,13 +2710,11 @@ sigar_net_interface_list_get(sigar_t *sigar,
/* special-case */
sprintf(name, NETIF_LA "%d", la++);
}
- else if (ifr->dwType == MIB_IF_TYPE_LOOPBACK) {
- sprintf(name, "lo%d", lo++);
- }
else if ((ifr->dwType == MIB_IF_TYPE_ETHERNET) ||
- (ifr->dwType == IF_TYPE_IEEE80211))
+ (ifr->dwType == IF_TYPE_IEEE80211) ||
+ (ifr->dwType == MIB_IF_TYPE_LOOPBACK))
{
- sprintf(name, "eth%d", eth++);
+ SIGAR_SSTRCPY(name, ifr->bDescr);
}
else {
continue; /*XXX*/
@@ -2725,6 +2723,7 @@ sigar_net_interface_list_get(sigar_t *sigar,
if (iflist) {
iflist->data[iflist->number++] = sigar_strdup(name);
}
+ fprintf(stderr,"> SIGAR iface: %s\n", name);
key = netif_hash(name);
entry = sigar_cache_get(sigar->netif_mib_rows, key);
--
1.7.3.5
13 years, 3 months
[PATCH] Sigar win32 network change
by Adam Stokes
- to insert adapter friendlyname based on hardware address
matching
There is still some work to be done as it looks like my best approach
would be to either:
a) create a lookup bridge table to pull the full friendly name
of the adapter since the length of the name array is
hardcoded to 16.
b) alter the hardcoded array length to allow for more
characters, however, this seems to prove problematic in my
tests. So far just simply altering the struct to something
like name[256] does not seem to be enough.
---
src/CMakeLists.txt | 11 +++++++-
src/os/win32/win32_sigar.c | 61 ++++++++++++++++++++++++++++++++-----------
2 files changed, 55 insertions(+), 17 deletions(-)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 40137d0..1091c81 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -100,8 +100,17 @@ SET(SIGAR_SRC ${SIGAR_SRC}
ADD_LIBRARY(sigar SHARED ${SIGAR_SRC})
IF(WIN32)
- TARGET_LINK_LIBRARIES(sigar ws2_32 netapi32 version)
+ TARGET_LINK_LIBRARIES(sigar ws2_32 netapi32 version iphlpapi)
ENDIF(WIN32)
+#glib
+include(FindPkgConfig)
+pkg_check_modules(glib REQUIRED glib-2.0)
+if(glib_FOUND)
+ include_directories(${glib_INCLUDE_DIRS})
+ target_link_libraries(sigar ${glib_LIBRARIES})
+else(glib_FOUND)
+ message(FATAL_ERROR "Glib2 header/library not found.")
+endif(glib_FOUND)
IF(SIGAR_LINK_FLAGS)
SET_TARGET_PROPERTIES(sigar PROPERTIES LINK_FLAGS "${SIGAR_LINK_FLAGS}")
ENDIF(SIGAR_LINK_FLAGS)
diff --git a/src/os/win32/win32_sigar.c b/src/os/win32/win32_sigar.c
index 87076c8..af55cf8 100755
--- a/src/os/win32/win32_sigar.c
+++ b/src/os/win32/win32_sigar.c
@@ -24,6 +24,8 @@
#include "sigar_format.h"
#include <shellapi.h>
#include <iphlpapi.h>
+#include <glib.h>
+#include <stdlib.h>
#define USING_WIDE_S(s) (s)->using_wide
#define USING_WIDE() USING_WIDE_S(sigar)
@@ -2671,13 +2673,17 @@ static int netif_hash(char *s)
#define IF_TYPE_IEEE80211 71
#endif
+#define GAA_FLAGS ( GAA_FLAG_SKIP_DNS_SERVER | GAA_FLAG_SKIP_MULTICAST | GAA_FLAG_SKIP_ANYCAST )
+#define IFACE_BUFSIZE 256
SIGAR_DECLARE(int)
sigar_net_interface_list_get(sigar_t *sigar,
sigar_net_interface_list_t *iflist)
{
MIB_IFTABLE *ift;
+ PIP_ADAPTER_ADDRESSES aa, addrs;
int i, status;
int lo=0, eth=0, la=0;
+ DWORD tableSize = 0;
if (!sigar->netif_mib_rows) {
sigar->netif_mib_rows =
@@ -2700,27 +2706,51 @@ sigar_net_interface_list_get(sigar_t *sigar,
malloc(sizeof(*(iflist->data)) * iflist->size);
}
+ GetAdaptersAddresses(AF_UNSPEC, GAA_FLAGS, NULL, aa, &tableSize);
+ aa = malloc(tableSize);
+ if ((status = GetAdaptersAddresses(AF_INET, GAA_FLAGS, NULL, aa, &tableSize)) != NO_ERROR)
+ return status;
+
for (i=0; i<ift->dwNumEntries; i++) {
char name[16];
int key;
MIB_IFROW *ifr = ift->table + i;
sigar_cache_entry_t *entry;
+ char *mac = NULL, *mac_cmp = NULL;
- if (strEQ(ifr->bDescr, MS_LOOPBACK_ADAPTER)) {
- /* special-case */
- sprintf(name, NETIF_LA "%d", la++);
- }
- else if (ifr->dwType == MIB_IF_TYPE_LOOPBACK) {
- sprintf(name, "lo%d", lo++);
- }
- else if ((ifr->dwType == MIB_IF_TYPE_ETHERNET) ||
- (ifr->dwType == IF_TYPE_IEEE80211))
- {
- sprintf(name, "eth%d", eth++);
- }
- else {
- continue; /*XXX*/
- }
+ if((ifr->dwType == MIB_IF_TYPE_ETHERNET) ||
+ (ifr->dwType == IF_TYPE_IEEE80211))
+ {
+ mac = g_strdup_printf("%02X%02X%02X%02X%02X%02X",
+ ifr->bPhysAddr[0],
+ ifr->bPhysAddr[1],
+ ifr->bPhysAddr[2],
+ ifr->bPhysAddr[3],
+ ifr->bPhysAddr[4],
+ ifr->bPhysAddr[5]);
+ for (addrs = aa; addrs; addrs = addrs->Next) {
+ if(addrs->PhysicalAddressLength < 6)
+ continue;
+ mac_cmp = g_strdup_printf("%02X%02X%02X%02X%02X%02X",
+ addrs->PhysicalAddress[0],
+ addrs->PhysicalAddress[1],
+ addrs->PhysicalAddress[2],
+ addrs->PhysicalAddress[3],
+ addrs->PhysicalAddress[4],
+ addrs->PhysicalAddress[5]);
+ if(strcmp(mac, mac_cmp) == 0) {
+ if ((status = wcstombs(name, addrs->FriendlyName, sizeof(name))) < 0) {
+ sprintf(name, "Windows Name to long");
+ }
+ } else {
+ sprintf(name, "eth%d", eth++);
+ }
+ }
+ }
+ else
+ {
+ continue; /* Just ethernet */
+ }
if (iflist) {
iflist->data[iflist->number++] = sigar_strdup(name);
@@ -2739,7 +2769,6 @@ sigar_net_interface_list_get(sigar_t *sigar,
entry->value = sigar_strdup(name);
}
}
-
return SIGAR_OK;
}
--
1.7.3.5
13 years, 3 months
[PATCH] Password option added
by Adam Stokes
- Added password option to use in conjunction with logging in to the brokers.
---
src/lib/mh_agent.cpp | 23 +++++++++++++++++++++--
1 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/src/lib/mh_agent.cpp b/src/lib/mh_agent.cpp
index 8a15202..9d0547d 100644
--- a/src/lib/mh_agent.cpp
+++ b/src/lib/mh_agent.cpp
@@ -92,6 +92,7 @@ struct option opt[] = {
{"broker", required_argument, NULL, 'b'},
{"gssapi", no_argument, NULL, 'g'},
{"username", required_argument, NULL, 'u'},
+ {"password", required_argument, NULL, 'P'},
{"service", required_argument, NULL, 's'},
{"port", required_argument, NULL, 'p'},
{0, 0, 0, 0}
@@ -100,12 +101,13 @@ struct option opt[] = {
static void
print_usage()
{
- printf("Usage:\tmatahari-netd <options>\n");
+ printf("Usage:\tmatahari-DAEMONd <options>\n");
printf("\t-d | --daemon run as a daemon.\n");
printf("\t-h | --help print this help message.\n");
printf("\t-b | --broker specify broker host name..\n");
printf("\t-g | --gssapi force GSSAPI authentication.\n");
printf("\t-u | --username username to use for authentication purproses.\n");
+ printf("\t-P | --password password to use for authentication purproses.\n");
printf("\t-s | --service service name to use for authentication purproses.\n");
printf("\t-p | --port specify broker port.\n");
}
@@ -140,6 +142,7 @@ MatahariAgent::init(int argc, char **argv, const char* proc_name)
bool gssapi = false;
char *servername = strdup(MATAHARI_BROKER);
char *username = NULL;
+ char *password = NULL;
char *service = NULL;
int serverport = MATAHARI_PORT;
int debuglevel = 0;
@@ -192,11 +195,16 @@ MatahariAgent::init(int argc, char **argv, const char* proc_name)
L"SYSTEM\\CurrentControlSet\\services\\Matahari",
L"User",
&username);
+ RegistryRead (
+ HKEY_LOCAL_MACHINE,
+ L"SYSTEM\\CurrentControlSet\\services\\Matahari",
+ L"Password",
+ &password);
#else
// Get args
- while ((arg = getopt_long(argc, argv, "hdb:gu:s:p:v", opt, &idx)) != -1) {
+ while ((arg = getopt_long(argc, argv, "hdb:gu:P:s:p:v", opt, &idx)) != -1) {
switch (arg) {
case 'h':
case '?':
@@ -226,6 +234,14 @@ MatahariAgent::init(int argc, char **argv, const char* proc_name)
exit(1);
}
break;
+ case 'P':
+ if (optarg) {
+ password = strdup(optarg);
+ } else {
+ print_usage();
+ exit(1);
+ }
+ break;
case 'g':
gssapi = true;
break;
@@ -279,6 +295,9 @@ MatahariAgent::init(int argc, char **argv, const char* proc_name)
if (username != NULL) {
settings.username = username;
}
+ if (password != NULL) {
+ settings.password = password;
+ }
if (service != NULL) {
settings.service = service;
}
--
1.7.3.4
13 years, 3 months
[PATCH] Alter win32_sigar network list
by Adam Stokes
- to match against HWADDR in order to properly insert
the windows friendlyName.
---
src/CMakeLists.txt | 36 +++++++++++++++++++
src/os/win32/sigar_os.h | 29 +++++++++++----
src/os/win32/win32_sigar.c | 83 ++++++++++++++++++++++++++++++++-----------
src/sigar_format.c | 2 +-
tests/t_sigar_fs.c | 4 +-
tests/t_sigar_proc.c | 4 +-
6 files changed, 124 insertions(+), 34 deletions(-)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 83548d1..0ef3a4d 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -4,6 +4,29 @@ MESSAGE(STATUS "CMAKE_SYSTEM_NAME is ${CMAKE_SYSTEM_NAME}")
INCLUDE_DIRECTORIES(../include/)
+INCLUDE(CheckCSourceCompiles)
+
+MACRO (CHECK_STRUCT_MEMBER _STRUCT _MEMBER _HEADER _RESULT)
+ SET(_INCLUDE_FILES)
+ FOREACH (it ${_HEADER})
+ SET(_INCLUDE_FILES "${_INCLUDE_FILES}#include <${it}>\n")
+ ENDFOREACH (it)
+
+ SET(_CHECK_STRUCT_MEMBER_SOURCE_CODE "
+${_INCLUDE_FILES}
+int main()
+{
+ static ${_STRUCT} tmp;
+ if (sizeof(tmp.${_MEMBER}))
+ return 0;
+ return 0;
+}
+")
+ CHECK_C_SOURCE_COMPILES("${_CHECK_STRUCT_MEMBER_SOURCE_CODE}" ${_RESULT})
+
+ENDMACRO (CHECK_STRUCT_MEMBER)
+
+
## linux
IF(CMAKE_SYSTEM_NAME STREQUAL "Linux")
SET(SIGAR_SRC os/linux/linux_sigar.c)
@@ -60,6 +83,8 @@ IF(WIN32)
ADD_DEFINITIONS(-DSIGAR_SHARED)
SET(SIGAR_SRC os/win32/peb.c os/win32/win32_sigar.c)
INCLUDE_DIRECTORIES(os/win32)
+ CHECK_STRUCT_MEMBER(MIB_IPADDRROW wType "windows.h;iphlpapi.h" wType_in_MIB_IPADDRROW)
+ add_definitions(-DHAVE_MIB_IPADDRROW_WTYPE=${wType_in_MIB_IPADDRROW})
ENDIF(WIN32)
SET(SIGAR_SRC ${SIGAR_SRC}
@@ -77,6 +102,17 @@ ADD_LIBRARY(sigar SHARED ${SIGAR_SRC})
IF(WIN32)
TARGET_LINK_LIBRARIES(sigar ws2_32 netapi32 version)
ENDIF(WIN32)
+
+#glib
+include(FindPkgConfig)
+pkg_check_modules(glib REQUIRED glib-2.0)
+if(glib_FOUND)
+ include_directories(${glib_INCLUDE_DIRS})
+ target_link_libraries(sigar ${glib_LIBRARIES})
+else(glib_FOUND)
+ message(FATAL_ERROR "Glib2 header/library not found.")
+endif(glib_FOUND)
+
IF(SIGAR_LINK_FLAGS)
SET_TARGET_PROPERTIES(sigar PROPERTIES LINK_FLAGS "${SIGAR_LINK_FLAGS}")
ENDIF(SIGAR_LINK_FLAGS)
diff --git a/src/os/win32/sigar_os.h b/src/os/win32/sigar_os.h
index ff2de7c..cd3c7e8 100755
--- a/src/os/win32/sigar_os.h
+++ b/src/os/win32/sigar_os.h
@@ -19,11 +19,15 @@
#ifndef SIGAR_OS_H
#define SIGAR_OS_H
+#ifdef MSVC
#if _MSC_VER <= 1200
#define SIGAR_USING_MSC6 /* Visual Studio version 6 */
#endif
+#else
+/* Cross compiling */
+#define _WIN32_WINNT 0x0501
+#endif
-#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <winreg.h>
#include <winperf.h>
@@ -38,7 +42,22 @@
#include "sigar_util.h"
-#define INT64_C(val) val##i64
+#ifdef MSVC
+# define INT64_C(val) val##i64
+# define SIGAR_DLLFUNC(api, name) \
+ struct { \
+ const char *name; \
+ ##api##_##name func; \
+ } ##name
+#else
+/* The GCC compiler doesn't require/accept the ## prefix */
+# define INT64_C(val) val##L
+# define SIGAR_DLLFUNC(api, name) \
+ struct { \
+ const char *name; \
+ api##_##name func; \
+ } name
+#endif
/* see apr/include/arch/win32/atime.h */
#define EPOCH_DELTA INT64_C(11644473600000000)
@@ -457,12 +476,6 @@ typedef BOOL (CALLBACK *mpr_get_net_connection)(LPCTSTR,
LPTSTR,
LPDWORD);
-#define SIGAR_DLLFUNC(api, name) \
- struct { \
- const char *name; \
- ##api##_##name func; \
- } ##name
-
typedef struct {
sigar_dll_handle_t handle;
diff --git a/src/os/win32/win32_sigar.c b/src/os/win32/win32_sigar.c
index b9a5669..aca9758 100755
--- a/src/os/win32/win32_sigar.c
+++ b/src/os/win32/win32_sigar.c
@@ -23,6 +23,8 @@
#include "sigar_util.h"
#include "sigar_format.h"
#include <shellapi.h>
+#include <iphlpapi.h>
+#include <glib.h>
#define USING_WIDE_S(s) (s)->using_wide
#define USING_WIDE() USING_WIDE_S(sigar)
@@ -124,6 +126,9 @@ typedef enum {
#define MS_LOOPBACK_ADAPTER "Microsoft Loopback Adapter"
#define NETIF_LA "la"
+static int get_proc_info(sigar_t *sigar, sigar_pid_t pid);
+static int netif_hash(char *s);
+
sigar_uint64_t sigar_FileTimeToTime(FILETIME *ft)
{
sigar_uint64_t time;
@@ -374,6 +379,7 @@ static sigar_mpr_t sigar_mpr = {
{ NULL, NULL }
};
+#ifdef MSVC
#define DLLMOD_COPY(name) \
memcpy(&(sigar->##name), &sigar_##name, sizeof(sigar_##name))
@@ -382,6 +388,18 @@ static sigar_mpr_t sigar_mpr = {
#define DLLMOD_FREE(name) \
sigar_dllmod_free((sigar_dll_module_t *)&(sigar->##name))
+#else
+/* The GCC compiler doesn't require/accept the ## prefix */
+#define DLLMOD_COPY(name) \
+ memcpy(&(sigar->name), &sigar_##name, sizeof(sigar_##name))
+
+#define DLLMOD_INIT(name, all) \
+ sigar_dllmod_init(sigar, (sigar_dll_module_t *)&(sigar->name), all)
+
+#define DLLMOD_FREE(name) \
+ sigar_dllmod_free((sigar_dll_module_t *)&(sigar->name))
+#endif
+
static void sigar_dllmod_free(sigar_dll_module_t *module)
{
@@ -1470,7 +1488,9 @@ static int sigar_remote_proc_args_get(sigar_t *sigar, sigar_pid_t pid,
}
/* likely we are 32-bit, pid process is 64-bit */
+#ifdef MSVC
status = sigar_proc_args_wmi_get(sigar, pid, procargs);
+#endif
if (status == ERROR_NOT_FOUND) {
status = SIGAR_NO_SUCH_PROCESS;
}
@@ -1507,7 +1527,7 @@ static int sigar_proc_env_parse(UCHAR *ptr, sigar_proc_env_t *procenv,
break; /*XXX*/
}
- klen = val - ptr;
+ klen = val - (char*)ptr;
SIGAR_SSTRCPY(key, ptr);
key[klen] = '\0';
++val;
@@ -1640,6 +1660,7 @@ SIGAR_DECLARE(int) sigar_proc_exe_get(sigar_t *sigar, sigar_pid_t pid,
}
status = sigar_proc_exe_peb_get(sigar, proc, procexe);
+#ifdef MSVC
if (procexe->name[0] == '\0') {
/* likely we are 32-bit, pid process is 64-bit */
/* procexe->cwd[0] = XXX where else can we try? */
@@ -1648,7 +1669,7 @@ SIGAR_DECLARE(int) sigar_proc_exe_get(sigar_t *sigar, sigar_pid_t pid,
status = SIGAR_NO_SUCH_PROCESS;
}
}
-
+#endif
if (procexe->cwd[0] != '\0') {
/* strip trailing '\' */
int len = strlen(procexe->cwd);
@@ -2394,10 +2415,10 @@ static int sigar_get_netif_ipaddr(sigar_t *sigar,
MIB_IPADDRROW *row = &mib->table[i];
short type;
-#ifdef SIGAR_USING_MSC6
- type = row->unused2;
-#else
+#if HAVE_MIB_IPADDRROW_WTYPE
type = row->wType;
+#else
+ type = row->unused2;
#endif
if (!(type & MIB_IPADDR_PRIMARY)) {
continue;
@@ -2682,24 +2703,44 @@ sigar_net_interface_list_get(sigar_t *sigar,
for (i=0; i<ift->dwNumEntries; i++) {
char name[16];
- int key;
+ char wName[256];
+ int key, r;
MIB_IFROW *ifr = ift->table + i;
+ PIP_ADAPTER_ADDRESSES aa, addrs;
sigar_cache_entry_t *entry;
-
- if (strEQ(ifr->bDescr, MS_LOOPBACK_ADAPTER)) {
- /* special-case */
- sprintf(name, NETIF_LA "%d", la++);
- }
- else if (ifr->dwType == MIB_IF_TYPE_LOOPBACK) {
- sprintf(name, "lo%d", lo++);
- }
- else if ((ifr->dwType == MIB_IF_TYPE_ETHERNET) ||
- (ifr->dwType == IF_TYPE_IEEE80211))
- {
- sprintf(name, "eth%d", eth++);
- }
- else {
- continue; /*XXX*/
+ char *mac, *mac_cmp;
+
+ mac = g_strdup_printf("%02X%02X%02X%02X%02X%02X",
+ ifr->bPhysAddr[0],
+ ifr->bPhysAddr[1],
+ ifr->bPhysAddr[2],
+ ifr->bPhysAddr[3],
+ ifr->bPhysAddr[4],
+ ifr->bPhysAddr[5]);
+ r = sigar_get_adapters_addresses(sigar, AF_INET, GAA_FLAG_INCLUDE_PREFIX, &aa);
+ if(r != SIGAR_OK)
+ return r;
+
+ for (addrs = aa; addrs; addrs = addrs->Next) {
+ mac_cmp = g_strdup_printf("%02X%02X%02X%02X%02X%02X",
+ addrs->PhysicalAddress[0],
+ addrs->PhysicalAddress[1],
+ addrs->PhysicalAddress[2],
+ addrs->PhysicalAddress[3],
+ addrs->PhysicalAddress[4],
+ addrs->PhysicalAddress[5]);
+ if(strcmp(mac, mac_cmp) != 0)
+ continue;
+ r = WideCharToMultiByte(CP_ACP,
+ 0,
+ addrs->FriendlyName,
+ -1,
+ wName,
+ sizeof(wName),
+ NULL,
+ NULL);
+ memset(name, 0, 256);
+ g_strlcpy(name, wName, 256);
}
if (iflist) {
diff --git a/src/sigar_format.c b/src/sigar_format.c
index 0ef9518..b1d6a0e 100644
--- a/src/sigar_format.c
+++ b/src/sigar_format.c
@@ -374,7 +374,7 @@ static char *sigar_inet_ntop(int af, const void *src, char *dst, int cnt)
return dst;
}
}
-#define sigar_inet_ntop_errno GetLastError()
+#define sigar_inet_ntop_errno SIGAR_ENOTIMPL
#else
#define sigar_inet_ntop inet_ntop
#define sigar_inet_ntop_errno errno
diff --git a/tests/t_sigar_fs.c b/tests/t_sigar_fs.c
index f298a08..7a554de 100644
--- a/tests/t_sigar_fs.c
+++ b/tests/t_sigar_fs.c
@@ -39,7 +39,7 @@
#include <stdio.h>
#include <string.h>
#include <errno.h>
-#if defined(_WIN32)
+#if defined(MSVC)
#include <WinError.h>
#endif
@@ -85,7 +85,7 @@ TEST(test_sigar_file_system_list_get) {
} else {
switch (ret) {
/* track the expected error code */
-#if defined(_WIN32)
+#if defined(MSVC)
case ERROR_NOT_READY:
break;
#endif
diff --git a/tests/t_sigar_proc.c b/tests/t_sigar_proc.c
index 88a9ac7..334bae3 100644
--- a/tests/t_sigar_proc.c
+++ b/tests/t_sigar_proc.c
@@ -39,7 +39,7 @@
#include <stdio.h>
#include <string.h>
#include <errno.h>
-#if defined(_WIN32)
+#if defined(MSVC)
#include <WinError.h>
#endif
@@ -127,7 +127,7 @@ TEST(test_sigar_proc_list_get) {
switch (ret) {
case EPERM:
case ESRCH:
-#if (defined(_WIN32))
+#if (defined(MSVC))
/* OpenProcess() may return ERROR_ACCESS_DENIED */
case ERROR_ACCESS_DENIED:
#endif
--
1.7.3.4
13 years, 3 months
mingw32 build with -Werror
by Adam Stokes
First issue ive run into is:
cc1: warnings being treated as errors
/home/akimbo/workspace/matahari/src/lib/network_linux.c: In function
‘network_os_start’:
/home/akimbo/workspace/matahari/src/lib/network_linux.c:40:9: error:
array subscript is above array bounds
/home/akimbo/workspace/matahari/src/lib/network_linux.c: In function
‘network_os_stop’:
/home/akimbo/workspace/matahari/src/lib/network_linux.c:59:9: error:
array subscript is above array bounds
Still investigating to try and verify if it has anything to do with:
http://gcc.gnu.org/bugzilla/buglist.cgi?query_format=specific&order=relev...
( adam stokes ) || ( adam.stokes(a)gmail.com )
13 years, 3 months
matahari/qpid w/ kerberos auth
by Perry Myers
The first pass at Matahari right now has zero auth on it, just a
username field to connect to a broker but no password. :)
Adam is working to add simple password auth to Matahari so that we have
some semblance of security.
But as Dmitri will point out, the real deal here is to get kerberos
integrated via IPA. Of course, qpid supports auth via kerberos, but
there are some practical matters we need to figure out.
Ignoring for a minute the issue of getting a machine its identity (which
Dmitri already covered separately), let's assume that the machine
already has a keytab file in place on the filesystem.
Ok, now we've got a keytab, but...
* How do we do the equivalent of kinit to load the identity and
authenticate to the KDC in an automated fashion? Kerberos tickets
generally have an expiration, so the 'kinit' would need to happen on
some sort of schedule? How is this done? (Note: crontab/at are not
good answers)
* Can/should we use keytab/identities that do not require a password to
create a ticket? Since we need automation here, adding a password is
sort of self-defeating anyhow
* What about Windows? If we're going to rely on Kerberos on Windows as
well, that means we need to preinstall some MIT kerb software on
Windows which means we need to pull it into Fedora and cross compile
it along with mingw32-matahari? Or do we just say "if you want to
use Matahari/Kerberos on Windows, here go download this MIT kerberos
windows installer from http://...."?
* Aside from installing either ipa RPMS on Fedora or MIT kerberos
software on Windows, there's the issue of configuring your OS to use
a KDC. Do we just declare that that is outside the scope of Matahari
install and state "if you want to use Kerberos auth, first make sure
your OS has the proper software and configuration to connect to a
KDC"?
Dmitri, thoughts? Just trying to figure out the practicalities of
making this easy to deploy and use for end-users on both Fedora and
Windows platforms.
Perry
13 years, 3 months
[PATCH] Network updates
by Adam Stokes
- Rewrite routines to utilize hash tables for faster lookup
- os variant specific listing of interfaces due to:
- sigar reports interfaces as 'ethX' independent of the OS.
- because of above we are unable to restart devices based on Windows
friendlyname (name shown in the device manager)
- make fewer sigar calls by letting all network routines run an
initialization routine beforehand.
---
src/include/matahari/network.h | 2 +-
src/lib/network.c | 111 +++++++++++++++------------------
src/lib/network_linux.c | 30 +++++++---
src/lib/network_private.h | 9 +++
src/lib/network_windows.c | 133 ++++++++++++++++++++++++++++++++++------
5 files changed, 196 insertions(+), 89 deletions(-)
diff --git a/src/include/matahari/network.h b/src/include/matahari/network.h
index d26133d..47620e2 100644
--- a/src/include/matahari/network.h
+++ b/src/include/matahari/network.h
@@ -22,7 +22,7 @@
#include <glib.h>
#include <stdint.h>
-extern GList *network_get_interfaces(void);
+extern GHashTable *network_get_interfaces(void);
extern const char *network_get_ip_address(const char *iface);
extern const char *network_get_mac_address(const char *iface);
diff --git a/src/lib/network.c b/src/lib/network.c
index 7b66094..0236f4f 100644
--- a/src/lib/network.c
+++ b/src/lib/network.c
@@ -29,38 +29,42 @@
MH_TRACE_INIT_DATA(mh_network);
-static GList *
-query_interface_table(void)
+network_init_t network_init = { NULL, FALSE };
+
+static void
+init(void)
{
- int status;
uint32_t lpc = 0;
- GList *interfaces = NULL;
- sigar_t* sigar;
+ int status;
sigar_net_interface_list_t iflist;
sigar_net_interface_config_t *ifconfig;
- sigar_open(&sigar);
- status = sigar_net_interface_list_get(sigar, &iflist);
+ if(network_init.sigar_init) return;
+ sigar_open(&network_init.sigar);
+ network_init.sigar_init = TRUE;
+ network_init.device_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
+ g_free, g_free);
+
+ status = sigar_net_interface_list_get(network_init.sigar, &iflist);
if(status == SIGAR_OK) {
- for(lpc = 0; lpc < iflist.number; lpc++) {
+ for(lpc; lpc < iflist.number; lpc++) {
ifconfig = g_new0(sigar_net_interface_config_t, 1);
- status = sigar_net_interface_config_get(sigar, iflist.data[lpc],
- ifconfig);
- if(status == SIGAR_OK)
- interfaces = g_list_prepend(interfaces, ifconfig);
+ status = sigar_net_interface_config_get(network_init.sigar,
+ iflist.data[lpc],
+ ifconfig);
+ g_hash_table_insert(network_init.device_hash,
+ (gpointer)ifconfig->name,
+ (gpointer)ifconfig);
}
- sigar_net_interface_list_destroy(sigar, &iflist);
}
- sigar_close(sigar);
- return interfaces;
}
-GList *
+GHashTable *
network_get_interfaces(void)
{
- GList *list = NULL;
- list = query_interface_table();
- return list;
+ init();
+ network_os_get_interfaces(&network_init);
+ return network_init.device_hash;
}
void
@@ -85,36 +89,27 @@ network_restart(const char *iface)
void
network_status(const char *iface, uint64_t *flags)
{
- GList *list = NULL;
- GList *plist;
- sigar_net_interface_config_t *ifconfig;
+ init();
+ sigar_net_interface_config_t *ifconfig = g_hash_table_lookup(network_init.device_hash,
+ iface);
- list = network_get_interfaces();
- for(plist = g_list_first(list); plist; plist = g_list_next(plist)) {
- ifconfig = (sigar_net_interface_config_t *)plist->data;
- if((g_str_equal(ifconfig->name, iface)) == TRUE) {
- *flags = ifconfig->flags;
- }
- }
+ if(ifconfig != NULL)
+ *flags = ifconfig->flags;
}
const char *
network_get_ip_address(const char *iface)
{
- GList *list = NULL;
- GList *plist;
- sigar_net_interface_config_t *ifconfig;
+ init();
+ sigar_net_interface_config_t *ifconfig = g_hash_table_lookup(network_init.device_hash,
+ iface);
char addr_str[SIGAR_INET6_ADDRSTRLEN];
- char *paddr_str;
-
- list = network_get_interfaces();
- for(plist = g_list_first(list); plist; plist = g_list_next(plist)) {
- ifconfig = (sigar_net_interface_config_t *)plist->data;
- if((g_str_equal(ifconfig->name, iface)) == TRUE) {
- sigar_net_address_to_string(NULL, &ifconfig->address, addr_str);
- paddr_str = g_strdup(addr_str);
- return paddr_str;
- }
+ char *paddr_str = NULL;
+
+ if(ifconfig != NULL) {
+ sigar_net_address_to_string(NULL, &ifconfig->address, addr_str);
+ paddr_str = g_strdup(addr_str);
+ return paddr_str;
}
return NULL;
}
@@ -122,24 +117,20 @@ network_get_ip_address(const char *iface)
const char *
network_get_mac_address(const char *iface)
{
- GList *list = NULL;
- GList *plist;
- sigar_net_interface_config_t *ifconfig;
- char *mac;
-
- list = network_get_interfaces();
- for(plist = g_list_first(list); plist; plist = g_list_next(plist)) {
- ifconfig = (sigar_net_interface_config_t *)plist->data;
- if((g_str_equal(ifconfig->name, iface)) == TRUE) {
- mac = g_strdup_printf("%.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
- ifconfig->hwaddr.addr.mac[0],
- ifconfig->hwaddr.addr.mac[1],
- ifconfig->hwaddr.addr.mac[2],
- ifconfig->hwaddr.addr.mac[3],
- ifconfig->hwaddr.addr.mac[4],
- ifconfig->hwaddr.addr.mac[5]);
- return mac;
- }
+ init();
+ sigar_net_interface_config_t *ifconfig = g_hash_table_lookup(network_init.device_hash,
+ iface);
+ char *mac = NULL;
+
+ if(ifconfig != NULL) {
+ mac = g_strdup_printf("%.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
+ ifconfig->hwaddr.addr.mac[0],
+ ifconfig->hwaddr.addr.mac[1],
+ ifconfig->hwaddr.addr.mac[2],
+ ifconfig->hwaddr.addr.mac[3],
+ ifconfig->hwaddr.addr.mac[4],
+ ifconfig->hwaddr.addr.mac[5]);
+ return mac;
}
return NULL;
}
diff --git a/src/lib/network_linux.c b/src/lib/network_linux.c
index 2fc1420..b48391e 100644
--- a/src/lib/network_linux.c
+++ b/src/lib/network_linux.c
@@ -21,18 +21,23 @@
*/
#include "matahari/network.h"
+#include "network_private.h"
#include <string.h>
+#include <glib.h>
void
network_os_start(const char *iface)
{
- char *argv[2];
+ char *argv[5];
gboolean ret;
GError *error = NULL;
- argv[0] = "/sbin/ifup";
- argv[1] = strdup(iface);
- argv[2] = NULL;
+ argv[0] = "/sbin/ip";
+ argv[1] = "link";
+ argv[2] = "set";
+ argv[3] = strdup(iface);
+ argv[4] = "up";
+ argv[5] = NULL;
ret = g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &error);
if(ret == FALSE) {
g_error_free(error);
@@ -42,15 +47,24 @@ network_os_start(const char *iface)
void
network_os_stop(const char *iface)
{
- char *argv[2];
+ char *argv[5];
gboolean ret;
GError *error = NULL;
- argv[0] = "/sbin/ifdown";
- argv[1] = strdup(iface);
- argv[2] = NULL;
+ argv[0] = "/sbin/ip";
+ argv[1] = "link";
+ argv[2] = "set";
+ argv[3] = strdup(iface);
+ argv[4] = "down";
+ argv[5] = NULL;
ret = g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &error);
if(ret == FALSE) {
g_error_free(error);
}
}
+
+void
+network_os_get_interfaces(network_init_t *network_init)
+{
+ /* nothing here */
+}
diff --git a/src/lib/network_private.h b/src/lib/network_private.h
index 04ba74f..adc9192 100644
--- a/src/lib/network_private.h
+++ b/src/lib/network_private.h
@@ -17,6 +17,15 @@
*/
#include <glib.h>
+#include <sigar.h>
+
+typedef struct network_init_s
+{
+ sigar_t *sigar;
+ gboolean sigar_init;
+ GHashTable *device_hash;
+} network_init_t;
extern void network_os_stop(const char *iface);
extern void network_os_start(const char *iface);
+extern void network_os_get_interfaces(network_init_t *network_init);
diff --git a/src/lib/network_windows.c b/src/lib/network_windows.c
index d735ef3..14c8eaa 100644
--- a/src/lib/network_windows.c
+++ b/src/lib/network_windows.c
@@ -25,11 +25,24 @@
#endif
#include "matahari/network.h"
+#include "network_private.h"
#include <config.h>
+#include <stdio.h>
+#include <string.h>
#include <glib.h>
#include <windows.h>
+#include <iphlpapi.h>
+#include <sigar.h>
+#include <sigar_private.h>
+#include <sigar_util.h>
+#include <sigar_format.h>
+
+#define GAA_FLAGS ( GAA_FLAG_SKIP_DNS_SERVER | GAA_FLAG_SKIP_MULTICAST | GAA_FLAG_SKIP_ANYCAST )
+#define BUFSIZE 256
+
+network_init_t win_network_init = {NULL, FALSE};
void
network_os_stop(const char *iface)
@@ -39,19 +52,23 @@ network_os_stop(const char *iface)
char *p;
char *exe_path;
+ ZeroMemory(&si, sizeof(si));
+ si.cb = sizeof(si);
+ ZeroMemory(&pi, sizeof(pi));
p = getenv("WINDIR");
exe_path = g_strdup_printf("%s\\system32\\netsh interface set interface %s disabled", p, iface);
- gboolean ok = CreateProcess(NULL,
- exe_path,
- NULL,
- NULL,
- TRUE,
- 0,
- NULL,
- NULL,
- &si,
- &pi);
+ CreateProcess(NULL,
+ exe_path,
+ NULL,
+ NULL,
+ TRUE,
+ 0,
+ NULL,
+ NULL,
+ &si,
+ &pi);
+ WaitForSingleObject(pi.hProcess, INFINITE);
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
@@ -66,21 +83,97 @@ network_os_start(const char *iface)
char *p;
char *exe_path;
+ ZeroMemory(&si, sizeof(si));
+ si.cb = sizeof(si);
+ ZeroMemory(&pi, sizeof(pi));
p = getenv("WINDIR");
exe_path = g_strdup_printf("%s\\system32\\netsh interface set interface %s enabled", p, iface);
- gboolean ok = CreateProcess(NULL,
- exe_path,
- NULL,
- NULL,
- TRUE,
- 0,
- NULL,
- NULL,
- &si,
- &pi);
+ CreateProcess(NULL,
+ exe_path,
+ NULL,
+ NULL,
+ TRUE,
+ 0,
+ NULL,
+ NULL,
+ &si,
+ &pi);
+ WaitForSingleObject(pi.hProcess, INFINITE);
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
g_free(exe_path);
}
+
+static void
+set_iface_mac_hash(void)
+{
+ DWORD tableSize = 0;
+ int r = 0;
+ char wName[BUFSIZE];
+ PIP_ADAPTER_ADDRESSES pAddresses = NULL, adapter = NULL;
+ char *mac;
+
+ GetAdaptersAddresses(AF_UNSPEC, GAA_FLAGS, NULL, pAddresses, &tableSize);
+ pAddresses = malloc(tableSize);
+ r = GetAdaptersAddresses(AF_INET, GAA_FLAGS, NULL, pAddresses, &tableSize);
+
+ win_network_init.device_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
+ g_free, g_free);
+
+ for(adapter = pAddresses; adapter; adapter = adapter->Next) {
+ if(adapter->PhysicalAddressLength < 6)
+ continue; /* not proper addr */
+ r = WideCharToMultiByte(CP_ACP,
+ 0,
+ adapter->FriendlyName,
+ -1,
+ wName,
+ sizeof(wName),
+ NULL,
+ NULL);
+
+ mac = g_strdup_printf("%02X%02X%02X%02X%02X%02X",
+ adapter->PhysicalAddress[0],
+ adapter->PhysicalAddress[1],
+ adapter->PhysicalAddress[2],
+ adapter->PhysicalAddress[3],
+ adapter->PhysicalAddress[4],
+ adapter->PhysicalAddress[5]);
+
+ g_hash_table_insert(win_network_init.device_hash,
+ (gpointer)mac,
+ (gpointer)wName);
+ g_free(mac);
+ }
+}
+
+void
+network_os_get_interfaces(network_init_t *network_init)
+{
+ GList *interface_list = NULL, *plist;
+ sigar_net_interface_config_t *ifconfig;
+ char *mac;
+ char *mac_cmp;
+
+ set_iface_mac_hash();
+ interface_list = g_hash_table_get_values(network_init->device_hash);
+ for (plist = g_list_first(interface_list); plist; plist = g_list_next(plist))
+ {
+ ifconfig = (sigar_net_interface_config_t *)plist->data;
+
+ mac = g_strdup_printf("%02X%02X%02X%02X%02X%02X",
+ ifconfig->hwaddr.addr.mac[0],
+ ifconfig->hwaddr.addr.mac[1],
+ ifconfig->hwaddr.addr.mac[2],
+ ifconfig->hwaddr.addr.mac[3],
+ ifconfig->hwaddr.addr.mac[4],
+ ifconfig->hwaddr.addr.mac[5]);
+ mac_cmp = g_hash_table_lookup(win_network_init.device_hash,
+ mac);
+ if(mac_cmp)
+ g_strlcpy(ifconfig->name, mac_cmp, BUFSIZE);
+ g_free(mac);
+ }
+}
--
1.7.3.4
13 years, 3 months